@@ -291,31 +291,32 @@ def __getattr__(self, name):
291291 raise AttributeError ("Marker name must NOT start with underscore" )
292292
293293 if self ._config is not None :
294- self ._update_markers (name )
294+ # We store a set of markers as a performance optimisation - if a mark
295+ # name is in the set we definitely know it, but a mark may be known and
296+ # not in the set. We therefore start by updating the set!
297+ if name not in self ._markers :
298+ for line in self ._config .getini ("markers" ):
299+ # example lines: "skipif(condition): skip the given test if..."
300+ # or "hypothesis: tests which use Hypothesis", so to get the
301+ # marker name we we split on both `:` and `(`.
302+ marker = line .split (":" )[0 ].split ("(" )[0 ].strip ()
303+ self ._markers .add (marker )
304+
305+ # If the name is not in the set of known marks after updating,
306+ # then it really is time to issue a warning or an error.
295307 if name not in self ._markers :
296- warnings .warn (
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 ,
301- )
302308 if self ._config .option .strict :
303309 fail ("{!r} not a registered marker" .format (name ), pytrace = False )
310+ else :
311+ warnings .warn (
312+ "Unknown pytest.mark.%s - is this a typo? You can register "
313+ "custom marks to avoid this warning - for details, see "
314+ "https://docs.pytest.org/en/latest/mark.html" % name ,
315+ UnknownMarkWarning ,
316+ )
304317
305318 return MarkDecorator (Mark (name , (), {}))
306319
307- def _update_markers (self , name ):
308- # We store a set of registered markers as a performance optimisation,
309- # but more could be added to `self._config` by other plugins at runtime.
310- # If we see an unknown marker, we therefore update the set and try again!
311- if name not in self ._markers :
312- for line in self ._config .getini ("markers" ):
313- # example lines: "skipif(condition): skip the given test if..."
314- # or "hypothesis: tests which use Hypothesis", so to get the
315- # marker name we we split on both `:` and `(`.
316- marker = line .split (":" )[0 ].split ("(" )[0 ].strip ()
317- self ._markers .add (marker )
318-
319320
320321MARK_GEN = MarkGenerator ()
321322
0 commit comments