MCPcopy Create free account
hub / github.com/pytest-dev/pytest / __getattr__

Method __getattr__

src/_pytest/mark/structures.py:495–534  ·  view source on GitHub ↗

Generate a new :class:`MarkDecorator` with the given name.

(self, name: str)

Source from the content-addressed store, hash-verified

493 self._markers: Set[str] = set()
494
495 def __getattr__(self, name: str) -> MarkDecorator:
496 """Generate a new :class:`MarkDecorator` with the given name."""
497 if name[0] == "_":
498 raise AttributeError("Marker name must NOT start with underscore")
499
500 if self._config is not None:
501 # We store a set of markers as a performance optimisation - if a mark
502 # name is in the set we definitely know it, but a mark may be known and
503 # not in the set. We therefore start by updating the set!
504 if name not in self._markers:
505 for line in self._config.getini("markers"):
506 # example lines: "skipif(condition): skip the given test if..."
507 # or "hypothesis: tests which use Hypothesis", so to get the
508 # marker name we split on both `:` and `(`.
509 marker = line.split(":")[0].split("(")[0].strip()
510 self._markers.add(marker)
511
512 # If the name is not in the set of known marks after updating,
513 # then it really is time to issue a warning or an error.
514 if name not in self._markers:
515 if self._config.option.strict_markers or self._config.option.strict:
516 fail(
517 f"{name!r} not found in `markers` configuration option",
518 pytrace=False,
519 )
520
521 # Raise a specific error for common misspellings of "parametrize".
522 if name in ["parameterize", "parametrise", "parameterise"]:
523 __tracebackhide__ = True
524 fail(f"Unknown '{name}' mark, did you mean 'parametrize'?")
525
526 warnings.warn(
527 "Unknown pytest.mark.%s - is this a typo? You can register "
528 "custom marks to avoid this warning - for details, see "
529 "https://docs.pytest.org/en/stable/how-to/mark.html" % name,
530 PytestUnknownMarkWarning,
531 2,
532 )
533
534 return MarkDecorator(Mark(name, (), {}, _ispytest=True), _ispytest=True)
535
536
537MARK_GEN = MarkGenerator(_ispytest=True)

Callers

nothing calls this directly

Calls 6

failFunction · 0.90
MarkDecoratorClass · 0.85
MarkClass · 0.85
stripMethod · 0.80
getiniMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected