Debugger doesn't stop at breakpoints with pytest if pytest-cov is used
See original GitHub issueEnvironment data
VS Code version: 1.19.3 Python Extension version: 2018.1.0 Python Version: 3.6.2 OS and version: Windows 10 latest update
Actual behavior
My initial setup has this setup.cfg file:
[tool:pytest]
addopts = --cov=mymodulename
This adds automatically a “–cov” to every “pytest” call, but prevents VSCode to stop at breakpoints. If I remove the file (or at least the --cov), I get back my breakpoints stop. I changed my setup to put that in my Travis file instead, but I feel like this should work 😕
Expected behavior
I should be able to have this file (and coverage) and debug at the same time.
Steps to reproduce:
- Install pytest and pytest-cov
- Create a setup.cfg as describe before
- Create even a simple test with a breakpoint inside
Issue Analytics
- State:
- Created 6 years ago
- Reactions:46
- Comments:30 (2 by maintainers)
Top Results From Across the Web
debugging of py.test does not stop on breakpoints if coverage ...
Workaround that worked for me to ignore pytest coverage settings in pyproject.toml is to edit the pytest configuration (in edit configurations) and add...
Read more >Unable to debug in pycharm with pytest - Stack Overflow
All the test suite is running ok in "Debug mode" but it doesn't stop on breakpoints. Debug Mode. I also have py.test as...
Read more >How to fix the issue: Debugging pytest is not working with ...
One common reason why PyCharm debugger is not able to stop at breakpoints is that something else is using the tracing api (sys.settrace)....
Read more >Debuggers and PyCharm — pytest-cov 4.0.0 documentation
This manifests itself in behaviour that PyCharm might not hit a breakpoint no matter what the user does, or encountering an error like...
Read more >Testing Python in Visual Studio Code
pytestArgs : Looks for any Python ( .py ) file whose name begins with "test_" ... VS Code doesn't stop at breakpoints while...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@lmazuel apologies for the delay. Looks like its not possible to debug the code with coverage enabled (http://pytest-cov.readthedocs.io/en/latest/debuggers.html). I guess we’ll have to disable ‘coverage’ on the fly when debugging (using the flag
"--no-cov"
).I use an alternative to @dferrante 's solution above, which seems to be seamless inside the VSCode IDE for
pytest
tests:In
setup.cfg
I have:And then in
launch.json
I define a new task:When you press the “Debug Test” button in the testing panel or by right-clicking on a test itself, VSCode executes this task which just turns off all coverage for that run. No need to switch between configurations or altering config arguments on the fly.
Note this may only work for fairly new versions of VSCode - I’m on 1.60.