Skip to content

Commit 3db52e4

Browse files
cwebster-99luabud
andauthored
Adding docs for test coverage (#7615)
* Adding docs for test coverage * Update docs/python/testing.md * Apply suggestions from code review * Update docs/python/testing.md * Update docs/python/testing.md * Adding gif * Apply suggestions from code review Co-authored-by: Luciana Abud <[email protected]> * Apply suggestions from code review * Updating cov gif * Update docs/python/testing.md --------- Co-authored-by: Luciana Abud <[email protected]>
1 parent 8400efd commit 3db52e4

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
Lines changed: 3 additions & 0 deletions
Loading

docs/python/testing.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,19 @@ Support for running tests in parallel with pytest is available through the `pyte
234234

235235
3. Run your tests, which will now be run in parallel.
236236

237+
## Run tests with coverage
238+
239+
Test coverage is a measure of how much of your code is covered by your tests, which can help you identify areas of your code that are not being fully tested. For more information on test coverage, visit VS Code's [Test Coverage documentation](/docs/editor/testing#_test-coverage.md).
240+
241+
To run tests with coverage enabled, select the coverage run icon in the Test Explorer or the “Run with coverage” option from any menu you normally trigger test runs from. The Python extension will run coverage using the [`pytest-cov`](https://pypi.org/project/pytest-cov/) plugin if you are using pytest, or with [`coverage.py`](https://coverage.readthedocs.io/) for unittest.
242+
> **Note**: Before running tests with coverage, make sure to install the correct testing coverage package for your project.
243+
244+
Once the coverage run is complete, lines will be highlighted in the editor for line level coverage. Test coverage results will appear as a "Test Coverage" sub-tab in the Test Explorer, which you can also navigate to with **Testing: Focus on Test Coverage View** in Command Palette (`F1)`). On this panel you can view line coverage metrics for each file and folder in your workspace.
245+
246+
![Gif showing running Python tests with coverage.](/docs/python/images/testing/python-coverage.gif)
247+
248+
For finer grain control of your coverage run when using pytest, you can edit the `python.testing.pytestArgs` setting to include your specifications. When the pytest argument `--cov` exists in `python.testing.pytestArgs`, the Python extension will make no additional edits to coverage args, to allow your customizations to take effect. If there is no `--cov` argument found, the extension will add `--cov=.` to the pytest args prior to run to enable coverage at the workspace root.
249+
237250
## Debug tests
238251

239252
You might occasionally need to step through and analyze tests in the debugger, either because the tests themselves have a code defect you need to track down or in order to better understand why an area of code being tested is failing. For more information on debugging or to understand how it works in VS Code, you can read the [Python debugging configurations](/docs/python/debugging.md) and general VS Code [Debugging](/docs/editor/debugging.md) articles.

0 commit comments

Comments
 (0)