pytest-codecov
raw JSON → 0.7.0 verified Fri May 01 auth: no python
Pytest plugin for uploading pytest-cov results (coverage reports) to codecov.io. Current version 0.7.0, released 2025-01-26, with support for Python >=3.8. Release cadence is irregular, with major updates every few years.
pip install pytest-codecov Common errors
error ValueError: Missing repository slug. Please set CODECOV_SLUG environment variable or provide it via --codecov-slug. ↓
cause The plugin cannot determine the repository slug automatically when running outside a git repo (e.g., in CI without git info).
fix
Set the environment variable CODECOV_SLUG to 'owner/repo' or use the --codecov-slug command-line option.
error pytest: error: unrecognized arguments: --cov ↓
cause pytest-cov is not installed or not activated.
fix
Install pytest-cov: pip install pytest-cov
Warnings
breaking In pytest-codecov 0.6.0+, the plugin uses the new Codecov upload endpoint. If you have a firewall or proxy, you may need to allow upload to upload.codecov.io instead of codecov.io. ↓
fix Update network rules to allow connections to upload.codecov.io.
gotcha The plugin only uploads when tests are run with pytest (not via other test runners). Ensure you are using pytest to execute tests. ↓
fix Run your tests using pytest command or pytest.main() in code.
gotcha If you use --cov-report= and set it to a value other than xml, the coverage report may not be uploaded. The plugin expects an XML report by default. ↓
fix Use --cov-report=xml or ensure cov-report is set to xml in pytest configuration.
deprecated The legacy Codecov uploader is deprecated. Consider migrating to codecov-cli for future-proofing. ↓
fix Install codecov-cli and follow its configuration; or use the --codecov-cli flag if available.
Imports
- pytest_codecov
import pytest_codecov
Quickstart
import pytest
import os
# Run pytest with coverage and upload to Codecov
# Set CODECOV_TOKEN as environment variable or in .codecov.yml
os.environ['CODECOV_TOKEN'] = os.environ.get('CODECOV_TOKEN', '')
# Run tests with coverage and JUnit XML (optional)
retcode = pytest.main([
'--cov=my_package',
'--cov-report=xml',
'--junit-xml=test-results.xml',
'tests/'
])
# The plugin automatically uploads to Codecov after tests finish