Framework Mode - Coverage thresholds
Folder Structure
tests/ ├── test_example.py ├── test_utils.py conftest.py pytest.ini requirements.txt # Coverage reports output folder coverage_reports/
tests/ ├── test_example.py ├── test_utils.py conftest.py pytest.ini requirements.txt # Coverage reports output folder coverage_reports/
tests/ folder, contains test scripts like test_example.py.conftest.py holds shared setup code and fixtures for tests.pytest.ini configures pytest and coverage plugin settings including coverage thresholds.coverage_reports/ folder for review.Use pytest.ini to configure coverage thresholds and reporting:
[pytest] addopts = --cov=src --cov-report=term-missing --cov-fail-under=80 # Explanation: # --cov=src : measure coverage for source code in src folder # --cov-report=term-missing : show missing lines in terminal # --cov-fail-under=80 : fail tests if coverage is below 80%
Adjust --cov-fail-under value to set your minimum coverage threshold.
For multiple environments or browsers, use environment variables or separate config files and load them in conftest.py.
--cov-report=xml option to create XML reports for CI tools.--cov-fail-under to prevent low-quality code from merging.pytest.ini or environment variables for easy updates.Where in this folder structure would you add a new coverage threshold setting for a different environment?