Skip to content

Commit

Permalink
Reword --cov-config caveat section and hopefully clear confusions. Cl…
Browse files Browse the repository at this point in the history
…oses #598.
  • Loading branch information
ionelmc committed Sep 15, 2024
1 parent 605daaa commit 2d41845
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ Caveats
A unfortunate consequence of coverage.py's history is that ``.coveragerc`` is a magic name: it's the default file but it also
means "try to also lookup coverage configuration in ``tox.ini`` or ``setup.cfg``".

In practical terms this means that if you have your coverage configuration in ``tox.ini`` or ``setup.cfg`` it is paramount
that you also use ``--cov-config=tox.ini`` or ``--cov-config=setup.cfg``.
In practical terms this means that if you have multiple configuration files around (``tox.ini``, ``pyproject.toml`` or ``setup.cfg``) you
might need to use ``--cov-config`` to make coverage use the correct configuration file.

You might not be affected but it's unlikely that you won't ever use ``chdir`` in a test.
Also, if you change the working directory and also use subprocesses in a test you might also need to use ``--cov-config`` to make pytest-cov
will use the expected configuration file in the subprocess.

This comment has been minimized.

Copy link
@mtvx

mtvx Sep 16, 2024

How about something like:

Configuration is looked up from files in this order:

1. ``.coveragerc``
2. ``tox.ini``
3. ``setup.cfg``

`pytest-cov` will simply pick the first file that exists, and try to load configuration from there. If you have a file mentioned higher in the list (e.g. `tox.ini`), but your `pytest-cov` configuration actually in a file later mentioned (e.g. `setup.cfg`), you need to explicitly point to the right configuration file with ``--cov-config {file}`.

The lookup is relative to the current working directory. So, if you change the working directory in a test, then you also need to point to the configuration file explicitly.

Reference
=========
Expand Down

0 comments on commit 2d41845

Please sign in to comment.