Solution skill
ImportError: cannot import name 'display_covered' from 'coverage.results'
Complete solution
Fixes ImportError for display_covered from coverage.results by upgrading pytest-cov and coverage together. Use when old pytest-cov meets new coverage. Not for a missing pytest-cov install.
TL;DR
Align your coverage and pytest-cov versions: python -m pip install -U pytest-cov coverage. Old pytest-cov imports display_covered from coverage.results, which newer coverage versions removed.
ImportError: cannot import name 'display_covered' from 'coverage.results'Fix it
Check versions. Run
python -m pip show pytest-cov coverage.- Expected: you will see an old pytest-cov (for example 3.x/4.x) next to a new coverage (7.x).
Upgrade both together. Run
python -m pip install -U pytest-cov coverage.- Expected:
Successfully installed pytest-cov-6.x coverage-7.x(or current).
- Expected:
Re-run. The plugin import should succeed now.
- Expected:
pytest --covstarts without the ImportError.
- Expected:
When this applies
- The traceback points at
pytest_cov/plugin.pyline doingfrom coverage.results import display_covered. - You pinned one of the two packages and let the other float.
When it does not apply
- If the error is about
coverage.report.Reporter, that is a different removed name. - If pytest-cov is not installed at all, install it first.
Tool compatibility
pytest-cov 5+ with coverage 7.x. Python 3.8+.
Why it happens
pytest-cov reaches into coverage's internals. When coverage refactors those internals (removing display_covered), old pytest-cov releases break. Upgrading pytest-cov gets the fixed import.
Edge cases
- If you must pin coverage (for example
coverage==6.5.0), pin a contemporary pytest-cov instead (4.x era).
Evidence
A real report of this exact traceback: pytestcov/plugin.py line 11 doing from coverage.results import displaycovered, failing against a newer coverage install. The issue was filed as pytest-dev/pytest-cov#670 with the full traceback showing the ImportError. The verified fix is aligning the two packages, upgrading pytest-cov to a release that matches the installed coverage. Source: https://github.com/pytest-dev/pytest-cov/issues/670.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_po0ufpXdkJHxdtYDUSvxxQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ImportError: cannot import name 'display_covered' from 'coverage.results' <span>— Vectle</span></a>