Test Overview
This test runs a simple function and uses pytest-cov to check how much of the code is covered by the test. It verifies that the coverage report shows 100% coverage for the tested function.
This test runs a simple function and uses pytest-cov to check how much of the code is covered by the test. It verifies that the coverage report shows 100% coverage for the tested function.
import pytest def add(a, b): return a + b def test_add(): assert add(2, 3) == 5 # To run coverage: pytest --cov=./ --cov-report=term-missing
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts by running pytest with coverage plugin enabled | Terminal ready to run pytest command | — | PASS |
| 2 | pytest discovers test_add function in test file | pytest test collection complete | — | PASS |
| 3 | pytest runs test_add which calls add(2, 3) | Function add executes and returns 5 | assert add(2, 3) == 5 | PASS |
| 4 | pytest-cov collects coverage data during test run | Coverage data recorded for add function | — | PASS |
| 5 | pytest finishes and prints coverage report showing 100% coverage for add function | Terminal displays coverage summary with no missing lines | Coverage report shows 100% coverage | PASS |
pytest-cov in your testing workflow?myapp?--cov=package_name.--cov=myapp, which is the correct syntax. pytest --cov tests/ would incorrectly target the tests directory instead of the myapp package.pytest --cov=myapp tests/test_module.py--cov=myapp option measures coverage for the myapp package, not tests.tests/test_module.py with coverage enabled will show coverage report for myapp code exercised by those tests.pytest --cov=myapp but no coverage report appeared. What is the most likely cause?app using pytest-cov. Which command should you run?--cov-report=html generates an HTML coverage report.--cov=app and --cov-report=html together.Pass the test and this pattern moves unknown