Skip to content

docs: explain migration from coverage run to pytest-cov - #763

Merged
ionelmc merged 1 commit into
pytest-dev:masterfrom
xuu33030:docs/482-coverage-migration
Oct 18, 2026
Merged

ionelmc merged 1 commit into
pytest-dev:masterfrom
xuu33030:docs/482-coverage-migration

Conversation

@xuu33030

Copy link
Copy Markdown
Contributor

Summary

  • Add a README section for coverage.py users explaining why switching from coverage run -m pytest to pytest --cov can change imports and reported coverage.
  • Recommend installing the package rather than depending on the working directory on sys.path, and point to the existing subprocess migration note.
  • Add the changelog entry and author attribution requested by CONTRIBUTING.

Closes #482.

Verification

  • In a clean temporary environment, coverage run -m pytest reported CWD on sys.path, whereas pytest --cov did not (same test file, both passed).
  • sphinx-build -b html -n -W docs <scratch-output>: passed before and after the change with no warnings.
  • git diff --check: passed.

This is a documentation-only change; the project's full tox matrix was not run. AI-assisted contribution; I reviewed the documentation, checked the behavior with an isolated reproducer, and ran the documentation build.

@ionelmc
ionelmc force-pushed the docs/482-coverage-migration branch from 4aedf1f to df4731b Compare October 18, 2026 16:35
@ionelmc
ionelmc merged commit 86bc608 into pytest-dev:master Oct 18, 2026
1 check was pending
Comment thread README.rst
``python -m``, which adds the current working directory to ``sys.path``. The latter uses the ``pytest`` command, which does
not add it automatically. If coverage drops unexpectedly after switching, check that the package under test is installed
in your environment (for example, with ``pip install -e .``) rather than relying on the working directory being importable.
Run ``pytest --cov=myproj tests/`` from the same environment to confirm that tests still import your package.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ionelmc are you sure this is the best advice? I'd point people at source = . in .coveragerc.toml along with the source_pkgs pointing at the importable instead of calling --cov with a value..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: Have a section for issues users coming from coverage may experience, surface it on or near the front page.

3 participants