-
Notifications
You must be signed in to change notification settings - Fork 174
Description
Background
This would be a continuation from #722. I would need this feature to implement post-mortem debugging for unit tests (nvim-neotest/neotest-python#23).
#722 discusses how the debugger could stop at an exception that would be thrown from an user code to a library code (e.g., pytest) using the "user uncaught" exception breakpoints (#111). However, I don't think it is enough to implement post-mortem debugging, because it will pause too aggressively at exceptions that regularly crosses the boundaries between user and library code as pointed out in #1102.
One quick example would be like this:
def test_foo():
with pytest.raises(SomeUserExpectedError):
_an_user_code_raises_exception() # <-- (A) The debugger will always stop here even if it's "expected"
assert "something has failed" # <---- (B) The debugger should stop here only
Because an exception that is thrown from a user code to the pytest framework will be considered as an "user uncaught" exception, it will hit a breakpoint on the line (A).
New feature: entering specific frames
In another issue #1102, I suggest implementing some filters or condition logics to control exception breakpoints in a more fine-grained manner, but we could also think of a feature to let the debugger enter specific stack frames in a post-mortem mode.
I was trying something like
tb = excinfo._excinfo[2]
debugpy.server.api._settrace(
suspend=True,
patch_multiprocessing=False,
stop_at_frame=tb.tb_frame,
)
but it does not work as pydevd.settrace
does not support stopping at or entering a frame that is not relevant with the current stacktrace (it just says Frame skipped from debugging during step-in.
).
Note: PuDB has such a feature!
PuDB allows to enter some specific stack frames obtained from a thrown exception.
dbg.interaction(frame, exc_tuple)
A use case can be found at pytest-pudb
: https://github.com/wronglink/pytest-pudb/blob/master/pytest_pudb.py#L100-L122.