@@ -48,6 +48,46 @@ def risky_operation():
4848
4949 session .request_continue ()
5050
51+ def test_post_mortem_basic_with_exception (pyfile , target , run ):
52+ """Can call post_mortem(e) with an exception alone."""
53+
54+ @pyfile
55+ def code_to_debug ():
56+ import debuggee
57+ debuggee .setup ()
58+
59+ import debugpy
60+
61+ def risky_operation ():
62+ raise ValueError ("something went wrong" ) # @raise
63+
64+ try :
65+ risky_operation ()
66+ except ValueError as e :
67+ debugpy .post_mortem (e )
68+
69+ with debug .Session () as session :
70+ with run (session , target (code_to_debug )):
71+ session .request ("setExceptionBreakpoints" , {"filters" : ["uncaught" ]})
72+
73+ occ = session .wait_for_next (
74+ Event ("stopped" ) | Event ("terminated" ),
75+ )
76+
77+ if occ .event == "terminated" :
78+ pytest .fail ("Debuggee exited without hitting breakpoint" )
79+
80+ exc_info = session .request ("exceptionInfo" , {"threadId" : occ .body ['threadId' ]})
81+ assert exc_info == some .dict .containing (
82+ {
83+ "exceptionId" : some .str .matching (r"(.+\.)?ValueError" ),
84+ "description" : "something went wrong" ,
85+ "breakMode" : "unhandled" ,
86+ }
87+ )
88+
89+ session .request_continue ()
90+
5191def test_post_mortem_basic_no_uncaught_breakpoint (pyfile , target , run ):
5292 """We don't stop if the uncaught exception breakpoint isn't set."""
5393
0 commit comments