Ask questionshow to configure for pytest and coverage
There are posts on sites that state
pytest-cov do not work together when debugging tests. More precisely
pytest-cov and debugging tests.
The solution is to use
--no-cov option with
pytest. Potential choices are:
"args": [ "--no-cov" ]in
"python.testing.pytestArgs": [ "--no-cov" ]in
--no-cov) when debugging, but have it enabled otherwise?
--no-covautomatically when debugging?
Answer questions kondratyev-nv
@BrendanSimon Thank you for the issue! I've tried to debug a pytest test with the pytest-cov installed, and I can confirm that the debugger won't stop at breakpoints with the coverage enabled (adding
--cov=<your module> to the
python.testing.pytestArgs). This happens because the Python Test Adapter uses a debugger from the Python extension which has a known issue https://github.com/Microsoft/vscode-python/issues/693. However, the test discovery and test execution work fine even with the coverage enabled. Also, Python Test Adapter does not use
launch.json. So, the right way to disable coverage is to add
"--no-cov" argument to the
python.testing.pytestArgs, see a note in the pytest configuration settings section - https://code.visualstudio.com/docs/python/testing#_pytest-configuration-settings.
Answering your other questions:
--cov=<your module>in the
python.testing.pytestArgsis used to debug and run your tests from the Test Explorer panel. If you want to see the coverage I suppose you have to either run it from the command line or create a config in
Related questionsNo questions were found.