From 4f6c67658c95ae45f4b5bdc5967aa9faab38640d Mon Sep 17 00:00:00 2001 From: Zac Hatfield-Dodds Date: Mon, 1 Apr 2019 12:38:33 +1100 Subject: [PATCH] Use mark-specific warning type So that we can ignore it in self-tests. --- src/_pytest/mark/structures.py | 10 +++++----- src/_pytest/warning_types.py | 9 +++++++++ tox.ini | 8 ++------ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index dfb358052..d96c0b126 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -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) diff --git a/src/_pytest/warning_types.py b/src/_pytest/warning_types.py index 55e1f037a..ffc6e69d6 100644 --- a/src/_pytest/warning_types.py +++ b/src/_pytest/warning_types.py @@ -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`. diff --git a/tox.ini b/tox.ini index 131bacae6..d0dd95ea3 100644 --- a/tox.ini +++ b/tox.ini @@ -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