emacs-lsp / dap-mode

Emacs :heart: Debug Adapter Protocol
https://emacs-lsp.github.io/dap-mode
GNU General Public License v3.0
1.29k stars 181 forks source link

dap-python: Support attaching debugger on assertion failures in pytest #506

Open TauPan opened 3 years ago

TauPan commented 3 years ago

pytest supports the --pdb and --pdbcls switches to launch a debugger if a test assertion fails:

  --pdb                 start the interactive Python debugger on errors or
                        KeyboardInterrupt.
  --pdbcls=modulename:classname
                        start a custom interactive Python debugger on errors.
                        For example:
                        --pdbcls=IPython.terminal.debugger:TerminalPdb

This is something that I use quite often so I would appreciate if dap-python could support it in some way.

Briefly glancing at the debugpy documentation and experimenting a bit it turns out that pytest tries to run the post_mortem method of that class https://docs.python.org/3/library/pdb.html#pdb.post_mortem which debugpy and its predecessor apparently do not support.

I think there may be some way to accomplish this with the current traceback and introspection and a custom class in python, but more reading and experimenting is necessary.

To elaborate: I think this could be done with a pytest plugin, which might be out of scope for dap-python, but I'm not sure what kind of support would be needed on dap-python's side.

TauPan commented 3 years ago

Another brief look at the vscode documentation turns up that apparently vscode doesn't support this... hmm... :-\

TauPan commented 3 years ago

Simply opening a feature request on debugpy yielded some valuable insight: https://github.com/microsoft/debugpy/issues/722#issuecomment-918043450 ... I can verify that I'm able to set "User Uncaught Exceptions" in dap-mode, however launching pytest from dap-debug will not pause in an assertion failure...

Paethon commented 2 years ago

Were you able to solve this somehow? For me, this would also be a pretty handy feature.

TauPan commented 2 years ago

Were you able to solve this somehow? For me, this would also be a pretty handy feature.

Not so far. Specifically not after updating dap-mode and the ms debugpy server just now.