Skip to content

Instantly share code, notes, and snippets.

@therightstuff
Last active October 6, 2022 08:19
Show Gist options
  • Save therightstuff/e30327ed98e76c74056db65950e45572 to your computer and use it in GitHub Desktop.
Save therightstuff/e30327ed98e76c74056db65950e45572 to your computer and use it in GitHub Desktop.
VSCode configuration for Python code coverage and debugging
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"env": {
"PYTEST_ADDOPTS": "--no-cov"
},
"justMyCode": false
}
]
}
{
"python.testing.pytestArgs": [
"--cov=<YOUR SOURCE FOLDER LOCATION>",
"--cov-report=html:htmlcov",
"<YOUR TEST FOLDER LOCATION>"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
}

VSCode configuration for Python code coverage and debugging

The .vscode/settings.json configuration will produce an HTML code coverage report for the source code folder and save it to the htmlcov folder.

NOTE: running an individual test via the test explorer will result in the code coverage report covering only that test.

The .vscode/launch.json configuration will disable code coverage for debugging sessions with the --no-cov flag, because the two features are incompatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment