Framework Mode - Branch coverage
Folder Structure
project-root/ ├── src/ │ └── calculator.py ├── tests/ │ ├── test_calculator.py │ ├── __init__.py │ └── conftest.py ├── pytest.ini ├── requirements.txt └── README.md
project-root/ ├── src/ │ └── calculator.py ├── tests/ │ ├── test_calculator.py │ ├── __init__.py │ └── conftest.py ├── pytest.ini ├── requirements.txt └── README.md
calculator.py with functions having branches (if/else).test_calculator.py where pytest test functions verify different branches of the code.Use pytest.ini to configure coverage options for branch coverage:
[pytest] addopts = --cov=src --cov-branch --cov-report=term-missing
This enables branch coverage measurement and shows missing branches in the terminal report.
For environment-specific settings (like test vs. dev), use environment variables or separate config files loaded in conftest.py.
pytest-cov plugin to generate coverage reports including branch coverage.
- name: Run tests with coverage
run: |
pytest --cov=src --cov-branch --cov-report=xml
Where in this folder structure would you add a new test to verify the false branch of a conditional in the calculator.py file?