Ask questionshow to configure for pytest and coverage

There are posts on sites that state pytest and 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 launch.json
  • "python.testing.pytestArgs": [ "--no-cov" ] in settings.json


  • Is this still necessary ?
  • How do I disable coverage (--no-cov) when debugging, but have it enabled otherwise?
  • Does Python Test Adaptor apply --no-cov automatically when debugging?
  • Which debug profile does Python Test Adaptor use?
  • Does it use a different launcher config for run veruss debug?
  • If so, how do I configure it?
  • Is there somewhere this is all documented? I can't see anything on Python Test Explorer pages.

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 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 -

Answering your other questions:

  • No, this is not necessary. Debugging works fine without --cov=<your module> in the python.testing.pytestArgs setting.
  • python.testing.pytestArgs is 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 launch.json.
  • No, it takes arguments from the python.testing.pytestArgs setting.
  • It does not use any config from the launch.json file.
  • They might be slightly different because of how the Python extension initialize debugging, but the most important things are taken from the settings, see Configuration section of README -
  • See the previous answer.
  • The Python Test Adapter's documentation is located in the file. If you would like to see any additional information there, feel free to create a PR or an issue describing what should be added. Some documentation for the testing with the Python extension can be found here

Related questions

No questions were found.
Nikolay Kondratyev kondratyev-nv Software developer with strong desire to learn and interest in large-scale software systems, web services, software design and architecture.
Github User Rank List