Skip to content

Commit f9c1638

Browse files
committed
feat: [report] partial_also setting
1 parent 7eeabeb commit f9c1638

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

CHANGES.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ upgrading your version of coverage.py.
2323
Unreleased
2424
----------
2525

26-
- A new configuration option: ":ref:`[run] patch <config_run_patch>`" lets you
26+
- A new configuration option: ":ref:`config_run_patch`" lets you
2727
specify named patches to apply to work around some limitations in coverage
2828
measurement. As of now, there is only one patch: ``os._exit`` lets coverage
2929
save its data even when :func:`os._exit() <python:os._exit>` is used to
@@ -34,6 +34,11 @@ Unreleased
3434
excluded as a line and ``if TYPE_CHECKING:`` is excluded as a branch. Closes
3535
`issue 831`_.
3636

37+
- A new configuration option: ":ref:`config_report_partial_also`" is a list of
38+
regexes to add as pragmas for partial branches. This parallels the
39+
":ref:`config_report_exclude_also`" setting for adding line exclusion
40+
patterns.
41+
3742
.. _issue 310: https://github.com/nedbat/coveragepy/issues/310
3843
.. _issue 312: https://github.com/nedbat/coveragepy/issues/312
3944
.. _issue 831: https://github.com/nedbat/coveragepy/issues/831

coverage/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ def __init__(self) -> None:
230230
self.report_omit: list[str] | None = None
231231
self.partial_always_list = DEFAULT_PARTIAL_ALWAYS[:]
232232
self.partial_list = DEFAULT_PARTIAL[:]
233+
self.partial_also: list[str] = []
233234
self.precision = 0
234235
self.report_contexts: list[str] | None = None
235236
self.show_missing = False
@@ -413,6 +414,7 @@ def copy(self) -> CoverageConfig:
413414
("include_namespace_packages", "report:include_namespace_packages", "boolean"),
414415
("partial_always_list", "report:partial_branches_always", "regexlist"),
415416
("partial_list", "report:partial_branches", "regexlist"),
417+
("partial_also", "report:partial_also", "regexlist"),
416418
("precision", "report:precision", "int"),
417419
("report_contexts", "report:contexts", "list"),
418420
("report_include", "report:include", "list"),
@@ -546,6 +548,7 @@ def post_process(self) -> None:
546548
for k, v in self.paths.items()
547549
}
548550
self.exclude_list += self.exclude_also
551+
self.partial_list += self.partial_also
549552

550553
def debug_info(self) -> list[tuple[str, Any]]:
551554
"""Make a list of (name, value) pairs for writing debug info."""

doc/config.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,22 @@ namespace packages`_, and are usually skipped.
742742
reporting. See :ref:`source` for details.
743743

744744

745+
.. _config_report_partial_also:
746+
747+
[report] partial_also
748+
.....................
749+
750+
(multi-string) A list of regular expressions. This setting is similar to
751+
:ref:`config_report_partial_branches`: it specifies patterns for branches to
752+
consider fully covered even if they don't exercise both destinations. This
753+
setting is preferred, because it will preserve the default exclude patterns
754+
like ``pragma: no branch`` instead of overwriting them.
755+
756+
See :ref:`config_report_partial_branches` for further details.
757+
758+
.. versionadded:: 7.10.0
759+
760+
745761
.. _config_report_partial_branches:
746762

747763
[report] partial_branches
@@ -751,7 +767,9 @@ reporting. See :ref:`source` for details.
751767
one of these regexes is excused from being reported as a partial branch. More
752768
details are in :ref:`branch`. If you use this option, you are replacing all
753769
the partial branch regexes so you'll need to also supply the "pragma: no
754-
branch" regex if you still want to use it.
770+
branch" regex if you still want to use it. The
771+
:ref:`config_report_partial_also` setting can be used to specify patterns
772+
without overwriting the default set.
755773

756774

757775
.. _config_report_precision:

tests/test_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,16 @@ def test_exclude_also(self) -> None:
493493
expected = coverage.config.DEFAULT_EXCLUDE + ["foobar", "raise .*Error"]
494494
assert cov.config.exclude_list == expected
495495

496+
def test_partial_also(self) -> None:
497+
self.make_file("pyproject.toml", """\
498+
[tool.coverage.report]
499+
partial_also = ["foobar", "raise .*Error"]
500+
""")
501+
cov = coverage.Coverage()
502+
503+
expected = coverage.config.DEFAULT_PARTIAL + ["foobar", "raise .*Error"]
504+
assert cov.config.partial_list == expected
505+
496506
def test_core_option(self) -> None:
497507
# Test that the core option can be set in the configuration file.
498508
self.del_environ("COVERAGE_CORE")

0 commit comments

Comments
 (0)