Registry / testing / pytest-cover

pytest-cover

JSON →
library3.0.0pypypiunverified

pytest-cover is a pytest plugin for measuring code coverage, which was forked from pytest-cov. The project was officially merged back into pytest-cov in January 2019, and its GitHub repository explicitly states to use pytest-cov instead. This library (version 3.0.0) is effectively abandoned and users are strongly advised to use the actively maintained `pytest-cov` for coverage reporting with pytest.

pip install pytest-cover
INSTALL
IMPORT
SIG · PYTEST-COVER
P
pytest-cover
testingpythonv3.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Since `pytest-cover` is abandoned, the quickstart illustrates usage for its successor, `pytest-cov`. It involves creating a simple Python module and a corresponding test file. The plugin integrates directly with `pytest` via command-line options. Running `pytest --cov=your_module` will execute tests and show a coverage report in the terminal. You can also generate an HTML report with `--cov-report=html`.

# This quickstart is for the recommended alternative: pytest-cov # Install required packages: pip install pytest pytest-cov # my_module.py def my_function(x): if x > 0: return x * 2 else: return 0 # test_my_module.py from my_module import my_function def test_positive_input(): assert my_function(5) == 10 def test_zero_input(): assert my_function(0) == 0 def test_negative_input(): assert my_function(-3) == 0 # To run tests and generate a coverage report (terminal output): # pytest --cov=my_module # To generate an HTML report: # pytest --cov=my_module --cov-report=html # Example of running the command (execute in your terminal where files are saved): # import os # os.system('pytest --cov=my_module') # os.system('pytest --cov=my_module --cov-report=html')
Debug
Known issues
breakingThe `pytest-cover` project is officially abandoned and has been merged back into `pytest-cov` since January 2019. Further development, bug fixes, or compatibility updates for `pytest-cover` are not expected. Using this library in new projects or maintaining it in existing ones is strongly discouraged.
fix
Migrate to `pytest-cov`. Uninstall `pytest-cover` (`pip uninstall pytest-cover`) and install `pytest-cov` (`pip install pytest-cov`). Review `pytest-cov`'s documentation for any specific migration steps or differences in configuration.
affects: 3.0.0 and older
gotchaOlder versions of `pytest-cover` (and `pytest-cov` before version 7) relied on `.pth` files for subprocess coverage measurement, which could lead to issues, especially with `easy_install` or specific uninstallation scenarios leaving stray files.
fix
If encountering unexpected coverage behavior related to subprocesses, ensure all remnants of `pytest-cover` (and older `pytest-cov` versions) are uninstalled. `pytest-cov` version 7+ replaced the `.pth` file approach with `coverage`'s patch options (e.g., `[run] concurrency = multiprocessing` and `patch = subprocess` in `.coveragerc`).
affects: All versions of pytest-cover
breakingGiven its abandonment in 2019, `pytest-cover` (version 3.0.0) is unlikely to be compatible with recent Python versions (e.g., Python 3.9+) or the latest versions of `pytest` itself, which frequently introduce breaking changes or drop support for older Python versions. For example, `pytest` 8 dropped support for Python 3.7.
fix
Use `pytest-cov` instead, which is actively maintained and supports modern Python versions (currently Python 3.9+ for `pytest-cov` 6.0.0+, and has dropped support for Python 3.8 in `pytest-cov` 6.0.0). Refer to `pytest-cov`'s changelog for specific Python and `pytest` version compatibility.
affects: All versions of pytest-cover when used with Python 3.8+ or pytest 7+
gotchaThe old `pytest-cover` README warned that for distributed testing, workers (slaves) must have `pytest-cover` installed, and environment variables for subprocess measurement must propagate. Similar considerations apply to `pytest-cov` with `pytest-xdist`.
fix
When using distributed testing with `pytest-xdist`, ensure `pytest-cov` (the recommended alternative) and `coverage` are installed in all worker environments. Configure `coverage` for parallel execution (e.g., `[run] parallel = true` in `.coveragerc`) to correctly combine results.
affects: All versions
Upgrade
Version history
3.0.0latest on PyPI · released Aug 1, 2015
Audit
Dependencies
pytestrequiredCore testing framework.
coveragerequiredUnderlying code coverage engine.
pytest-xdistoptionalFor distributed testing support (optional, as per original project README).
Agent activity
2 hits · last 30 days
node
2
Resources
pytest-cover — pip install pytest-cover · libregistry