Skip to content

Does not consult files at project root #692

Open

Description

@madduck

Summary

If pytest runs in e.g. ./tests/, it reads ../pyproject.toml for configuration options, and that squares with my expectation. pytest-cov does seem to look only for ./pyproject.toml (and also writes ./.coverage instead of keeping that file at the project root), and that causes it to run with different settings depending on where pytest is invoked.

Case in point, I have this in my config:

[tool.coverage.report]
exclude_also = [
  'def __repr__',
]

If I run pytest from the project root directory, I get 100% coverage. If I run it from the tests/ subdirectory, all __repr__ functions, which I don't test, get reports as uncovered.

Reproducer

Versions

pytest                       8.3.5
pytest-cov                   6.1.1
coverage                     7.8.0

Python 3.13.3

Activity

  1. DawnofGenX commented on Oct 6, 2026

    @DawnofGenX
    Contributor

    /take

    Reproduced on current master (0ad139c): [tool.coverage.report] exclude_also is honoured when pytest runs from the project root (100%) but ignored when run from tests/ (the excluded def __repr__ shows as missing, 80%). The cause is that coverage.py resolves its config relative to the cwd while pytest's rootdir is the project root. I'll look at how --cov-config / the coverage config file is resolved.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions