Skip to content

TPI: test python branch coverage #25014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
eleanorjboyd opened this issue Apr 25, 2025 · 0 comments
Closed
3 tasks done

TPI: test python branch coverage #25014

eleanorjboyd opened this issue Apr 25, 2025 · 0 comments

Comments

@eleanorjboyd
Copy link
Member

eleanorjboyd commented Apr 25, 2025

Refs: #24980

Complexity: 4

Author: @eleanorjboyd

Create Issue

Create Issue


βœ… 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
@eleanorjboyd eleanorjboyd added the feature-request Request for new features or functionality label Apr 25, 2025
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Apr 25, 2025
@eleanorjboyd eleanorjboyd added testplan-item and removed feature-request Request for new features or functionality triage-needed Needs assignment to the proper sub-team labels Apr 25, 2025
@joaomoreno joaomoreno added this to the April 2025 milestone Apr 25, 2025
@jrieken jrieken removed their assignment Apr 28, 2025
@karthiknadig karthiknadig removed their assignment Apr 28, 2025
@amunger amunger removed their assignment Apr 28, 2025
@amunger amunger closed this as completed Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants