Home > Mobile >  Is there a way to have the python debugger always pause before exiting?
Is there a way to have the python debugger always pause before exiting?

Time:09-15

I can set breakpoints, but often I just want to look at some variables after I run a test.

Is there a way to debug a pytest test in vscode and just have it always pause before exiting? Without me setting break points or writing pause statements?

CodePudding user response:

You can set specific final actions from within pytest tearDown methods:

pytest_runtest_teardown(item, nextitem)

pytest_runtest_makereport(item, call)

pytest_runtest_logreport(report)

pytest_exception_interact(call, report)

(More info on that here: https://docs.pytest.org/en/latest/reference/reference.html)

These methods can exist in a conftest.py file.

Eg:

def pytest_runtest_teardown(item):
    ...
    # Do something after every test that runs.

This existing Stack Overflow solution can give you a good start on possible implementations: https://stackoverflow.com/a/40446593/7058266

From there, you can have your tests do whatever you want... print variables, use breakpoints, etc.

  • Related