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

Class MarkDecorator

src/_pytest/mark/structures.py:270–360  ·  view source on GitHub ↗

A decorator for applying a mark on test functions and classes. ``MarkDecorators`` are created with ``pytest.mark``:: mark1 = pytest.mark.NAME # Simple MarkDecorator mark2 = pytest.mark.NAME(name1=value) # Parametrized MarkDecorator and can then be applied as d

Source from the content-addressed store, hash-verified

268
269@attr.s(init=False, auto_attribs=True)
270class MarkDecorator:
271 """A decorator for applying a mark on test functions and classes.
272
273 ``MarkDecorators`` are created with ``pytest.mark``::
274
275 mark1 = pytest.mark.NAME # Simple MarkDecorator
276 mark2 = pytest.mark.NAME(name1=value) # Parametrized MarkDecorator
277
278 and can then be applied as decorators to test functions::
279
280 @mark2
281 def test_function():
282 pass
283
284 When a ``MarkDecorator`` is called, it does the following:
285
286 1. If called with a single class as its only positional argument and no
287 additional keyword arguments, it attaches the mark to the class so it
288 gets applied automatically to all test cases found in that class.
289
290 2. If called with a single function as its only positional argument and
291 no additional keyword arguments, it attaches the mark to the function,
292 containing all the arguments already stored internally in the
293 ``MarkDecorator``.
294
295 3. When called in any other case, it returns a new ``MarkDecorator``
296 instance with the original ``MarkDecorator``'s content updated with
297 the arguments passed to this call.
298
299 Note: The rules above prevent a ``MarkDecorator`` from storing only a
300 single function or class reference as its positional argument with no
301 additional keyword or positional arguments. You can work around this by
302 using `with_args()`.
303 """
304
305 mark: Mark
306
307 def __init__(self, mark: Mark, *, _ispytest: bool = False) -> None:
308 """:meta private:"""
309 check_ispytest(_ispytest)
310 self.mark = mark
311
312 @property
313 def name(self) -> str:
314 """Alias for mark.name."""
315 return self.mark.name
316
317 @property
318 def args(self) -> Tuple[Any, ...]:
319 """Alias for mark.args."""
320 return self.mark.args
321
322 @property
323 def kwargs(self) -> Mapping[str, Any]:
324 """Alias for mark.kwargs."""
325 return self.mark.kwargs
326
327 @property

Callers 2

with_argsMethod · 0.85
__getattr__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected