{"id":344,"library":"coverage","title":"Coverage.py: Code Coverage Measurement for Python","description":"Coverage.py is a tool for measuring code coverage of Python programs, currently at version 7.13.5, released on March 17, 2026. It is actively maintained with regular updates addressing various issues and enhancements.","status":"active","version":"7.13.5","language":"python","source_language":"en","source_url":"https://github.com/coveragepy/coveragepy","tags":["code coverage","testing","Python"],"install":[{"cmd":"pip install coverage","lang":"bash","label":"Install Coverage.py"}],"dependencies":[{"reason":"Commonly used for running tests in conjunction with Coverage.py","package":"pytest","optional":true}],"imports":[{"note":"Ensure correct import path to access the Coverage class","symbol":"Coverage","correct":"from coverage import Coverage"}],"quickstart":{"code":"import os\nfrom coverage import Coverage\n\n# Start coverage measurement\ncov = Coverage()\ncov.start()\n\n# Your code to test\n# ...\n\n# Stop coverage measurement\ncov.stop()\n\n# Generate HTML report\ncov.html_report(directory=os.environ.get('COVERAGE_REPORT_DIR', 'covhtml'))","lang":"python","description":"Basic usage of Coverage.py to measure code coverage and generate an HTML report."},"warnings":[{"fix":"Upgrade to version 7.11.3 or later to restore previous behavior.","message":"In version 7.11.1, conflicts between a requested measurement core and other settings raised an error, which was a breaking change from previous behavior. This has been restored in version 7.11.3 to use another core instead and issue a warning.","severity":"breaking","affected_versions":"7.11.1"},{"fix":"Upgrade to version 7.11.2 or later to resolve this issue.","message":"When using the 'sysmon' measurement core in version 7.11.1, a 'NotPython' exception could be raised if Python code was claimed to come from a non-Python file, such as Jinja templates compiled to Python. This issue has been fixed in version 7.11.2.","severity":"gotcha","affected_versions":"7.11.1"},{"fix":"Ensure that the target code is executed when coverage is active and that data collection and saving are configured correctly. Verify the execution environment and paths. Consult the 'coverage.py' documentation on 'No data collected' for detailed troubleshooting.","message":"The 'coverage' library failed with a 'NoDataError' during report generation because no data was collected. This typically happens when the code intended for coverage measurement is not executed or when coverage data files are not properly saved or loaded in the current environment.","severity":"breaking","affected_versions":"coverage:7.10.7"},{"fix":"Ensure that Python code intended for coverage measurement is executed under `coverage.py`'s control (e.g., using `coverage run <your_script.py>`) and that coverage data is saved before attempting to report it (e.g., `coverage combine`, `coverage html`). Verify that the executed script actually runs the relevant code.","message":"The `coverage.exceptions.NoDataError: No data to report.` occurs when no Python code is executed or recorded by the Coverage.py tool, leading to no coverage data being collected. This is often preceded by a `CoverageWarning: No data was collected. (no-data-collected)` message.","severity":"gotcha","affected_versions":"7.13.5"}],"env_vars":null,"last_verified":"2026-05-12T13:11:43.370Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Review your `coverage run` command and configuration file (`.coveragerc`): ensure `--source` or `[run] source` correctly points to the directories containing your code, add `__init__.py` files to your directories if they are Python packages, and check for conflicts where other tools might be overriding `sys.settrace`.","cause":"Coverage.py ran the program but did not measure any lines as executed, often due to incorrect `--source`, `--include`, or `--omit` configurations, or the code not actually being imported/run within the scope of measurement.","error":"Coverage.py warning: No data was collected. (no-data-collected)"},{"fix":"Run coverage using `python -m coverage run` to ensure it uses the same Python interpreter and its associated environment as your regular script execution. Additionally, ensure your project's root or relevant paths are correctly added to `PYTHONPATH` or specified via `coverage run --source`.","cause":"When `coverage run` executes your script, it might be using a different Python interpreter or environment where the necessary modules are not installed or are not discoverable in `sys.path`.","error":"ModuleNotFoundError: No module named 'your_module'"},{"fix":"After running `coverage run` with `parallel=True` (or similar parallel execution setup), you need to combine the individual `.coverage.*` data files into a single `.coverage` file using `coverage combine` before running `coverage report` or `coverage html`.","cause":"This often occurs after running tests in parallel (e.g., with `pytest-xdist`) where each process saves its coverage data to a separate file, and these files have not been combined before generating the report.","error":"No data to report."},{"fix":"Adjust the `[run] source` setting in `.coveragerc` to prevent measurement of code outside your project. Alternatively, use `[report] omit` to explicitly skip reporting on temporary directories (e.g., `omit=$TMPDIR/*`), or set `[report] ignore_errors = true` to treat the error as a warning.","cause":"Coverage.py traced a source file during execution but could not find the file when attempting to generate a report, often because the file was temporary and deleted, or located outside the configured source/include paths.","error":"No source for code: 'filename.py'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.24,"mem_mb":9.7,"disk_size":"19.2M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.16,"mem_mb":9.7,"disk_size":"20M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.5,"mem_mb":10.4,"disk_size":"21.3M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.29,"mem_mb":10.4,"disk_size":"22M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.33,"mem_mb":10.2,"disk_size":"13.1M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.3,"mem_mb":10.2,"disk_size":"14M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.33,"mem_mb":10.5,"disk_size":"12.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.28,"mem_mb":10.5,"disk_size":"13M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.23,"mem_mb":9.6,"disk_size":"18.7M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.2,"mem_mb":9.6,"disk_size":"19M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}