Test Overview
This test runs pytest with coverage measurement and verifies that the code coverage meets the minimum threshold set in the configuration. It ensures that the tested code is sufficiently covered by tests.
This test runs pytest with coverage measurement and verifies that the code coverage meets the minimum threshold set in the configuration. It ensures that the tested code is sufficiently covered by tests.
import subprocess import sys def test_coverage_threshold(): # Run pytest with coverage and fail if coverage is below threshold result = subprocess.run([ sys.executable, "-m", "pytest", "--cov=src", "--cov-fail-under=80" ], capture_output=True, text=True) # Check that pytest exited with code 0 (success) assert result.returncode == 0, f"Coverage threshold not met:\n{result.stdout}\n{result.stderr}"
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts by running pytest with coverage options and threshold set to 80% | Terminal ready to execute pytest command | - | PASS |
| 2 | Subprocess runs pytest with --cov=src and --cov-fail-under=80 | Pytest runs tests and measures coverage on 'src' folder | - | PASS |
| 3 | Pytest finishes and returns exit code | Coverage report generated, exit code indicates pass/fail | Check if return code is 0 (coverage >= 80%) | PASS |
| 4 | Assert that coverage threshold is met | Test framework receives assertion result | Assert result.returncode == 0 | PASS |