Coverage for pyquickhelper/pycode/trace_execution.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-03 02:21 +0200

1""" 

2@brief 

3@file Various function to help investigate an error. 

4""" 

5import traceback 

6from io import StringIO 

7 

8 

9class ErrorOnPurpose(Exception): 

10 """ 

11 raise to get the call stack 

12 """ 

13 pass 

14 

15 

16def get_call_stack(): 

17 """ 

18 Returns a string showing the call stack 

19 when this function is called. 

20 

21 .. exref:: 

22 :title: Display the call stack 

23 

24 .. runpython:: 

25 :showcode: 

26 

27 from pyquickhelper.pycode import get_call_stack 

28 print(get_call_stack()) 

29 """ 

30 s = StringIO() 

31 traceback.print_stack(file=s) 

32 return s.getvalue()