forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
Milestone
Description
Refs: #24980
- macOS @jrieken
- linux @karthiknadig
- windows @amunger
Complexity: 4
Author: @eleanorjboyd
β Test Plan: Verify Coverage Integration for Pytest & Unittest
π Objective
Ensure test branch coverage is correctly reported in VS Code using both pytest and unittest, and that the results align with the command-line coverage output (with minor rounding differences expected).
π§ͺ Repo & Project Info
Project Structure:
coverage-example-repo/
βββ src/
β βββ math_utils.py
βββ test/
β βββ test_math_utils_pytest.py
β βββ test_math_utils_unittest.py
βββ requirements.txt
βββ README.md
π Setup
Clone this repo: coverage-example-repo
git clone https://github.com/eleanorjboyd/coverage-example-repo
cd coverage-example-repo
In VS Code, open the Command Palette β Python: Create Environment
If the UI does not prompt to install requirements, run:
pip install -r requirements.txt
β Part 1: Test with Pytest
- Open the Testing tab in VS Code
- Select pytest as the test framework
- Click the 3rd run button (
βΆοΈ with checkmark) to run tests with coverage - Coverage results are visible
- Branch coverage is shown
- Coverage numbers look reasonable
β Part 2: Test with Unittest
- Change the test framework to unittest (settings.json or VS Code UI)
- Update any necessary args in python.testing.unittestArgs
- Click the same 3rd run button to run tests with coverage
- Confirm:
- Coverage results are visible
- Branch coverage is shown
- Coverage numbers make sense and are comparable to pytest
β Part 3: Cross-check with CLI Coverage
- Run tests with pytest from the CLI:
coverage run --branch -m pytest
coverage report
Erase and re-run with unittest:
coverage erase
coverage run --branch -m unittest discover -s test
coverage report
Confirm:
- CLI coverage output branch coverage is the same as the output from the UI
β οΈ Note: minor rounding differences are expected