Search code examples
pythondocker-composepytestvscode-debugger

Pytest - Breakpoints in tests are being skipped when debugging with VSCode


In the python module integration_tests I have a script to run my tests via pytest in the file run_tests.py:

import pytest

if __name__ == "__main__":    
    pytest.main(['./integration_tests/']) # breakpoint here works, but no breakpoints in test methods

In my docker-compose.yml file I attach a debugger and run the tests by setting the entrypoint:

entrypoint: ["/usr/src/app/cvenv/bin/python3.8", "-m", "ptvsd", "--host", "0.0.0.0", "--port", "5678", "--wait", "./integration_tests/run_tests.py"]

The breakpoint in the run_tests.py file works. But no breakpoints after that are being executed.

How can I really debug the tests and not just until the pytest call?


Solution

  • I didn't know that I can use the -m module switch twice. So now I added the -m pytest switch to the entrypoint command with the ptvsd debugging option. Now this command runs the visual studio debugger and calls the tests.

    I couldn't debug the tests using the pytest.main call because it creates a seperate thread.