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

Class Mark

src/_pytest/mark/structures.py:248–312  ·  view source on GitHub ↗

A pytest mark.

Source from the content-addressed store, hash-verified

246@final
247@dataclasses.dataclass(frozen=True)
248class Mark:
249 """A pytest mark."""
250
251 #: Name of the mark.
252 name: str
253 #: Positional arguments of the mark decorator.
254 args: tuple[Any, ...]
255 #: Keyword arguments of the mark decorator.
256 kwargs: Mapping[str, Any]
257
258 #: Source Mark for ids with parametrize Marks.
259 _param_ids_from: Mark | None = dataclasses.field(default=None, repr=False)
260 #: Resolved/generated ids with parametrize Marks.
261 _param_ids_generated: Sequence[str] | None = dataclasses.field(
262 default=None, repr=False
263 )
264
265 def __init__(
266 self,
267 name: str,
268 args: tuple[Any, ...],
269 kwargs: Mapping[str, Any],
270 param_ids_from: Mark | None = None,
271 param_ids_generated: Sequence[str] | None = None,
272 *,
273 _ispytest: bool = False,
274 ) -> None:
275 """:meta private:"""
276 check_ispytest(_ispytest)
277 # Weirdness to bypass frozen=True.
278 object.__setattr__(self, "name", name)
279 object.__setattr__(self, "args", args)
280 object.__setattr__(self, "kwargs", kwargs)
281 object.__setattr__(self, "_param_ids_from", param_ids_from)
282 object.__setattr__(self, "_param_ids_generated", param_ids_generated)
283
284 def _has_param_ids(self) -> bool:
285 return "ids" in self.kwargs or len(self.args) >= 4
286
287 def combined_with(self, other: Mark) -> Mark:
288 """Return a new Mark which is a combination of this
289 Mark and another Mark.
290
291 Combines by appending args and merging kwargs.
292
293 :param Mark other: The mark to combine with.
294 :rtype: Mark
295 """
296 assert self.name == other.name
297
298 # Remember source of ids with parametrize Marks.
299 param_ids_from: Mark | None = None
300 if self.name == "parametrize":
301 if other._has_param_ids():
302 param_ids_from = other
303 elif self._has_param_ids():
304 param_ids_from = self
305

Callers 3

combined_withMethod · 0.85
with_argsMethod · 0.85
__getattr__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected