Skip to content

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

@TauPan

Description

@TauPan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions