From 048abb60bfa112810e4a566639177d2666017e2e Mon Sep 17 00:00:00 2001 From: Max Berkowitz Date: Thu, 25 Apr 2024 23:15:38 -0400 Subject: [PATCH] Add helper function to MarkGenerator to verify a mark is registered --- src/_pytest/mark/structures.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index a6503bf1d..c60cf6da3 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -520,11 +520,7 @@ class MarkGenerator: self._config: Optional[Config] = None self._markers: Set[str] = set() - def __getattr__(self, name: str) -> MarkDecorator: - """Generate a new :class:`MarkDecorator` with the given name.""" - if name[0] == "_": - raise AttributeError("Marker name must NOT start with underscore") - + def verify_mark(self, name: str) -> None: if self._config is not None: # We store a set of markers as a performance optimisation - if a mark # name is in the set we definitely know it, but a mark may be known and @@ -556,9 +552,16 @@ class MarkGenerator: "custom marks to avoid this warning - for details, see " "https://docs.pytest.org/en/stable/how-to/mark.html" % name, PytestUnknownMarkWarning, - 2, + 3, ) + def __getattr__(self, name: str) -> MarkDecorator: + """Generate a new :class:`MarkDecorator` with the given name.""" + if name[0] == "_": + raise AttributeError("Marker name must NOT start with underscore") + + self.verify_mark(name) + return MarkDecorator(Mark(name, (), {}, _ispytest=True), _ispytest=True)