Skip to content

Commit 4f6c676

Browse files
committed
Use mark-specific warning type
So that we can ignore it in self-tests.
1 parent cda9ce1 commit 4f6c676

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/_pytest/mark/structures.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ..compat import MappingMixin
1212
from ..compat import NOTSET
1313
from _pytest.outcomes import fail
14-
from _pytest.warning_types import PytestWarning
14+
from _pytest.warning_types import UnknownMarkWarning
1515

1616
EMPTY_PARAMETERSET_OPTION = "empty_parameter_set_mark"
1717

@@ -294,10 +294,10 @@ def __getattr__(self, name):
294294
self._update_markers(name)
295295
if name not in self._markers:
296296
warnings.warn(
297-
"Unknown mark %r. You can register custom marks to avoid this "
298-
"warning, without risking typos that break your tests. See "
299-
"https://docs.pytest.org/en/latest/mark.html for details." % name,
300-
PytestWarning,
297+
"Unknown pytest.mark.%s - is this a typo? You can register "
298+
"custom marks to avoid this warning - for details, see "
299+
"https://docs.pytest.org/en/latest/mark.html" % name,
300+
UnknownMarkWarning,
301301
)
302302
if self._config.option.strict:
303303
fail("{!r} not a registered marker".format(name), pytrace=False)

src/_pytest/warning_types.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ class PytestWarning(UserWarning):
99
"""
1010

1111

12+
class UnknownMarkWarning(PytestWarning):
13+
"""
14+
Bases: :class:`PytestWarning`.
15+
16+
Warning emitted on use of unknown markers.
17+
See https://docs.pytest.org/en/latest/mark.html for details.
18+
"""
19+
20+
1221
class PytestDeprecationWarning(PytestWarning, DeprecationWarning):
1322
"""
1423
Bases: :class:`pytest.PytestWarning`, :class:`DeprecationWarning`.

tox.ini

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,11 @@ filterwarnings =
165165
ignore::pytest.PytestExperimentalApiWarning
166166
# Do not cause SyntaxError for invalid escape sequences in py37.
167167
default:invalid escape sequence:DeprecationWarning
168+
# ignore use of unregistered marks, because we use many to test the implementation
169+
ignore::_pytest.warning_types.UnknownMarkWarning
168170
pytester_example_dir = testing/example_scripts
169171
markers =
170172
issue
171-
nothing
172-
foo
173-
bar
174-
baz
175-
xyz
176-
XYZ
177173

178174
[flake8]
179175
max-line-length = 120

0 commit comments

Comments
 (0)