Skip to content

Commit 0a9266f

Browse files
committed
📝 Update test coverage
* Links to articles and tools * Add tip not to omit tests from coverage
1 parent a0d9c58 commit 0a9266f

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

docs/test/pytest/coverage.rst

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,13 @@ an editor and view the missing lines. However, it is easier to look at the HTML
159159
report.
160160

161161
.. seealso::
162-
* `pytest-cov’s documentation <https://pytest-cov.readthedocs.io/>`_
162+
* `covdefaults <https://pypi.org/project/covdefaults/>`_: A coverage plugin
163+
to provide sensible default settings
164+
* `coverage-conditional-plugin
165+
<https://pypi.org/project/coverage-conditional-plugin/>`_: Conditional
166+
coverage based on any rules you define
167+
* `Coverage.py regex pragmas
168+
<https://nedbatchelder.com/blog/202507/coveragepy_regex_pragmas.html>`_
163169

164170
Generate HTML reports
165171
~~~~~~~~~~~~~~~~~~~~~
@@ -304,12 +310,34 @@ Alternatively, this can also be configured for all occurrences:
304310
`Configuration reference
305311
<https://coverage.readthedocs.io/en/latest/config.html>`_
306312

313+
.. _coverage_tip:
314+
315+
.. tip::
316+
Many people exclude tests from test coverage: `omit tests
317+
path:**/pyproject.toml
318+
<https://github.com/search?q=omit+tests+path%3A**%2Fpyproject.toml&type=code>`_.
319+
However, this is a bad idea. Your tests are real code, and the whole point of
320+
test coverage is to give you information about your code. Why wouldn’t you
321+
want this information about your tests?
322+
323+
You might say, *‘All my tests run the entire code, so it’s useless
324+
information.’* However, if you write a new test and copy an existing test for
325+
it, changing only the execution but not the function name, only one of the
326+
two test functions will be executed. And are you sure that every piece of
327+
helper code in your test suite is still needed? Coverage would alert you to
328+
this problem in both cases.
329+
330+
One argument against test coverage is that it artificially inflates the
331+
reports. But you can easily exclude these files from the report with
332+
`[report] skip_covered
333+
<https://coverage.readthedocs.io/en/latest/config.html#report-skip-covered>`_.
334+
307335
Extensions
308336
----------
309337

310338
In `Coverage.py plugins
311-
<https://gist.github.com/nedbat/2e9dbf7f33b1e0e857368af5c5d06202>`_ you will also
312-
find a number of extensions for Coverage.
339+
<https://gist.github.com/nedbat/2e9dbf7f33b1e0e857368af5c5d06202>`_, you will
340+
also find other extensions for Coverage.
313341

314342
.. _coverage-github-actions:
315343

0 commit comments

Comments
 (0)