MCPcopy
hub / github.com/pytest-dev/pytest / __getattr__

Method __getattr__

src/_pytest/mark/structures.py:594–636  ·  view source on GitHub ↗

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

(self, name: str)

Source from the content-addressed store, hash-verified

592 self._markers: set[str] = set()
593
594 def __getattr__(self, name: str) -> MarkDecorator:
595 """Generate a new :class:`MarkDecorator` with the given name."""
596 if name[0] == "_":
597 raise AttributeError("Marker name must NOT start with underscore")
598
599 if self._config is not None:
600 # We store a set of markers as a performance optimisation - if a mark
601 # name is in the set we definitely know it, but a mark may be known and
602 # not in the set. We therefore start by updating the set!
603 if name not in self._markers:
604 for line in self._config.getini("markers"):
605 # example lines: "skipif(condition): skip the given test if..."
606 # or "hypothesis: tests which use Hypothesis", so to get the
607 # marker name we split on both `:` and `(`.
608 marker = line.split(":")[0].split("(")[0].strip()
609 self._markers.add(marker)
610
611 # If the name is not in the set of known marks after updating,
612 # then it really is time to issue a warning or an error.
613 if name not in self._markers:
614 # Raise a specific error for common misspellings of "parametrize".
615 if name in ["parameterize", "parametrise", "parameterise"]:
616 __tracebackhide__ = True
617 fail(f"Unknown '{name}' mark, did you mean 'parametrize'?")
618
619 strict_markers = self._config.getini("strict_markers")
620 if strict_markers is None:
621 strict_markers = self._config.getini("strict")
622 if strict_markers:
623 fail(
624 f"{name!r} not found in `markers` configuration option",
625 pytrace=False,
626 )
627
628 warnings.warn(
629 f"Unknown pytest.mark.{name} - is this a typo? You can register "
630 "custom marks to avoid this warning - for details, see "
631 "https://docs.pytest.org/en/stable/how-to/mark.html",
632 PytestUnknownMarkWarning,
633 2,
634 )
635
636 return MarkDecorator(Mark(name, (), {}, _ispytest=True), _ispytest=True)
637
638
639MARK_GEN = MarkGenerator(_ispytest=True)

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected