Skip to content

Commit 99babbf

Browse files
committedMay 9, 2023
docs: lean harder on [report] exclude_also.
1 parent 4cbe7f8 commit 99babbf

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed
 

‎doc/config.rst

+14-17
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ Here's a sample configuration file::
7979

8080
[report]
8181
# Regexes for lines to exclude from consideration
82-
exclude_lines =
83-
# Have to re-enable the standard pragma
84-
pragma: no cover
85-
82+
exclude_also =
8683
# Don't complain about missing debug-only code:
8784
def __repr__
8885
if self\.debug
@@ -375,6 +372,19 @@ See :ref:`cmd_combine_remapping` and :ref:`source_glob` for more information.
375372
Settings common to many kinds of reporting.
376373

377374

375+
.. _config_report_exclude_also:
376+
377+
[report] exclude_also
378+
.....................
379+
380+
(multi-string) A list of regular expressions. This setting is similar to
381+
:ref:`config_report_exclude_lines`: it specifies patterns for lines to exclude
382+
from reporting. This setting is preferred, because it will preserve the
383+
default exclude patterns instead of overwriting them.
384+
385+
.. versionadded:: 7.2.0
386+
387+
378388
.. _config_report_exclude_lines:
379389

380390
[report] exclude_lines
@@ -397,19 +407,6 @@ you'll exclude any line with three or more of any character. If you write
397407
``pass``, you'll also exclude the line ``my_pass="foo"``, and so on.
398408

399409

400-
.. _config_report_exclude_also:
401-
402-
[report] exclude_also
403-
.....................
404-
405-
(multi-string) A list of regular expressions. This setting is similar to
406-
:ref:`config_report_exclude_lines`: it specifies patterns for lines to exclude
407-
from reporting. The difference is this setting will preserve the default
408-
exclude patterns instead of overwriting them.
409-
410-
.. versionadded:: 7.2.0
411-
412-
413410
.. _config_report_fail_under:
414411

415412
[report] fail_under

‎doc/excluding.rst

+6-8
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,13 @@ debugging code, and are uninteresting to test themselves. You could exclude
8080
all of them by adding a regex to the exclusion list::
8181

8282
[report]
83-
exclude_lines =
83+
exclude_also =
8484
def __repr__
8585

8686
For example, here's a list of exclusions I've used::
8787

8888
[report]
89-
exclude_lines =
90-
pragma: no cover
89+
exclude_also =
9190
def __repr__
9291
if self.debug:
9392
if settings.DEBUG
@@ -99,11 +98,10 @@ For example, here's a list of exclusions I've used::
9998
class .*\bProtocol\):
10099
@(abc\.)?abstractmethod
101100

102-
Note that when using the ``exclude_lines`` option in a configuration file, you
103-
are taking control of the entire list of regexes, so you need to re-specify the
104-
default "pragma: no cover" match if you still want it to apply. The
105-
``exclude_also`` option can be used instead to preserve the default
106-
exclusions while adding new ones.
101+
The :ref:`config_report_exclude_also` option adds regexes to the built-in
102+
default list so that you can add your own exclusions. The older
103+
:ref:`config_report_exclude_lines` option completely overwrites the list of
104+
regexes.
107105

108106
The regexes only have to match part of a line. Be careful not to over-match. A
109107
value of ``...`` will match any line with more than three characters in it.

‎doc/migrating.rst

+7
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ Migrating from 6.x to 7.x
2727
- When remapping file paths with ``[paths]``, a path will be remapped only if
2828
the resulting path exists. Ensure that remapped ``[paths]`` exist when upgrading
2929
as this is now being enforced.
30+
31+
- The :ref:`config_report_exclude_also` setting is new in 7.2.0. It adds
32+
exclusion regexes while keeping the default built-in set. It's better than
33+
the older :ref:`config_report_exclude_lines` setting, which overwrote the
34+
entire list. Newer versions of coverage.py will be adding to the default set
35+
of exclusions. Using ``exclude_also`` will let you benefit from those
36+
updates.

0 commit comments

Comments
 (0)
Please sign in to comment.