Use mark-specific warning type

So that we can ignore it in self-tests.
This commit is contained in:
Zac Hatfield-Dodds 2019-04-01 12:38:33 +11:00
parent cda9ce198a
commit 4f6c67658c
3 changed files with 16 additions and 11 deletions

View File

@ -11,7 +11,7 @@ from ..compat import getfslineno
from ..compat import MappingMixin
from ..compat import NOTSET
from _pytest.outcomes import fail
from _pytest.warning_types import PytestWarning
from _pytest.warning_types import UnknownMarkWarning
EMPTY_PARAMETERSET_OPTION = "empty_parameter_set_mark"
@ -294,10 +294,10 @@ class MarkGenerator(object):
self._update_markers(name)
if name not in self._markers:
warnings.warn(
"Unknown mark %r. You can register custom marks to avoid this "
"warning, without risking typos that break your tests. See "
"https://docs.pytest.org/en/latest/mark.html for details." % name,
PytestWarning,
"Unknown pytest.mark.%s - is this a typo? You can register "
"custom marks to avoid this warning - for details, see "
"https://docs.pytest.org/en/latest/mark.html" % name,
UnknownMarkWarning,
)
if self._config.option.strict:
fail("{!r} not a registered marker".format(name), pytrace=False)

View File

@ -9,6 +9,15 @@ class PytestWarning(UserWarning):
"""
class UnknownMarkWarning(PytestWarning):
"""
Bases: :class:`PytestWarning`.
Warning emitted on use of unknown markers.
See https://docs.pytest.org/en/latest/mark.html for details.
"""
class PytestDeprecationWarning(PytestWarning, DeprecationWarning):
"""
Bases: :class:`pytest.PytestWarning`, :class:`DeprecationWarning`.

View File

@ -165,15 +165,11 @@ filterwarnings =
ignore::pytest.PytestExperimentalApiWarning
# Do not cause SyntaxError for invalid escape sequences in py37.
default:invalid escape sequence:DeprecationWarning
# ignore use of unregistered marks, because we use many to test the implementation
ignore::_pytest.warning_types.UnknownMarkWarning
pytester_example_dir = testing/example_scripts
markers =
issue
nothing
foo
bar
baz
xyz
XYZ
[flake8]
max-line-length = 120