Skip to content

Improve config snippets in code exclusion docs #1917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions doc/excluding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ all of them by adding a regex to the exclusion list:
[tool.coverage.report]
exclude_also = [
"def __repr__",
]
]
""",
)
.. ]]]
Expand All @@ -124,7 +124,7 @@ all of them by adding a regex to the exclusion list:
[tool.coverage.report]
exclude_also = [
"def __repr__",
]
]

.. code-tab:: ini
:caption: setup.cfg or tox.ini
Expand All @@ -133,7 +133,7 @@ all of them by adding a regex to the exclusion list:
exclude_also =
def __repr__

.. [[[end]]] (checksum: e3194120285bcbac38a92b109edaa20c)
.. [[[end]]] (checksum: f3e70ebf128fbef4087efe75dcfadcb8)

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

Expand All @@ -156,17 +156,17 @@ For example, here's a list of exclusions I've used:
toml=r"""
[tool.coverage.report]
exclude_also = [
"def __repr__",
"if self.debug:",
"if settings.DEBUG",
"raise AssertionError",
"raise NotImplementedError",
"if 0:",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
"class .*\\bProtocol\\):",
"@(abc\\.)?abstractmethod",
]
'def __repr__',
'if self.debug:',
'if settings.DEBUG',
'raise AssertionError',
'raise NotImplementedError',
'if 0:',
'if __name__ == .__main__.:',
'if TYPE_CHECKING:',
'class .*\bProtocol\):',
'@(abc\.)?abstractmethod',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL that single- and double-quotes have different semantics. I would rather use single quotes for all strings instead of mixing the styles.

Also, make sure the cog process that produces the files still works properly. You need to run make cogdoc to be sure.

]
""",
)
.. ]]]
Expand Down Expand Up @@ -194,17 +194,17 @@ For example, here's a list of exclusions I've used:

[tool.coverage.report]
exclude_also = [
"def __repr__",
"if self.debug:",
"if settings.DEBUG",
"raise AssertionError",
"raise NotImplementedError",
"if 0:",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
"class .*\\bProtocol\\):",
"@(abc\\.)?abstractmethod",
]
'def __repr__',
'if self.debug:',
'if settings.DEBUG',
'raise AssertionError',
'raise NotImplementedError',
'if 0:',
'if __name__ == .__main__.:',
'if TYPE_CHECKING:',
'class .*\bProtocol\):',
'@(abc\.)?abstractmethod',
]

.. code-tab:: ini
:caption: setup.cfg or tox.ini
Expand All @@ -222,7 +222,7 @@ For example, here's a list of exclusions I've used:
class .*\bProtocol\):
@(abc\.)?abstractmethod

.. [[[end]]] (checksum: 91f09828a1e6d0e92543e14a8ea3ba39)
.. [[[end]]] (checksum: 650b209edd27112381b5f0a8d2ee0c45)

The :ref:`config_report_exclude_also` option adds regexes to the built-in
default list so that you can add your own exclusions. The older
Expand Down Expand Up @@ -270,12 +270,12 @@ Here are some examples:
[tool.coverage.report]
exclude_also = [
# 1. Exclude an except clause of a specific form:
"except ValueError:\\n\\s*assume\\(False\\)",
'except ValueError:\n\s*assume\(False\)',
# 2. Comments to turn coverage on and off:
"no cover: start(?s:.)*?no cover: stop",
'no cover: start(?s:.)*?no cover: stop',
# 3. A pragma comment that excludes an entire file:
"\\A(?s:.*# pragma: exclude file.*)\\Z",
]
'\A(?s:.*# pragma: exclude file.*)\Z',
]
""",
)
.. ]]]
Expand All @@ -300,12 +300,12 @@ Here are some examples:
[tool.coverage.report]
exclude_also = [
# 1. Exclude an except clause of a specific form:
"except ValueError:\\n\\s*assume\\(False\\)",
'except ValueError:\n\s*assume\(False\)',
# 2. Comments to turn coverage on and off:
"no cover: start(?s:.)*?no cover: stop",
'no cover: start(?s:.)*?no cover: stop',
# 3. A pragma comment that excludes an entire file:
"\\A(?s:.*# pragma: exclude file.*)\\Z",
]
'\A(?s:.*# pragma: exclude file.*)\Z',
]

.. code-tab:: ini
:caption: setup.cfg or tox.ini
Expand All @@ -319,7 +319,7 @@ Here are some examples:
; 3. A pragma comment that excludes an entire file:
\A(?s:.*# pragma: exclude file.*)\Z

.. [[[end]]] (checksum: ee3ef14b5a5d73f987b924df623a4927)
.. [[[end]]] (checksum: c46e819ad9a1d3a8e37037a89d28cfde)

The first regex matches a specific except line followed by a specific function
call. Both lines must be present for the exclusion to take effect. Note that
Expand Down
Loading