@@ -268,14 +268,14 @@ def combined_with(self, other: "Mark") -> "Mark":
268
268
# A generic parameter designating an object to which a Mark may
269
269
# be applied -- a test function (callable) or class.
270
270
# Note: a lambda is not allowed, but this can't be represented.
271
- _Markable = TypeVar ("_Markable " , bound = Union [Callable [..., object ], type ])
271
+ Markable = TypeVar ("Markable " , bound = Union [Callable [..., object ], type ])
272
272
273
273
274
- @attr .s
274
+ @attr .s ( init = False , auto_attribs = True )
275
275
class MarkDecorator :
276
276
"""A decorator for applying a mark on test functions and classes.
277
277
278
- MarkDecorators are created with ``pytest.mark``::
278
+ `` MarkDecorators`` are created with ``pytest.mark``::
279
279
280
280
mark1 = pytest.mark.NAME # Simple MarkDecorator
281
281
mark2 = pytest.mark.NAME(name1=value) # Parametrized MarkDecorator
@@ -286,7 +286,7 @@ class MarkDecorator:
286
286
def test_function():
287
287
pass
288
288
289
- When a MarkDecorator is called it does the following:
289
+ When a `` MarkDecorator`` is called, it does the following:
290
290
291
291
1. If called with a single class as its only positional argument and no
292
292
additional keyword arguments, it attaches the mark to the class so it
@@ -295,19 +295,24 @@ def test_function():
295
295
2. If called with a single function as its only positional argument and
296
296
no additional keyword arguments, it attaches the mark to the function,
297
297
containing all the arguments already stored internally in the
298
- MarkDecorator.
298
+ `` MarkDecorator`` .
299
299
300
- 3. When called in any other case, it returns a new MarkDecorator instance
301
- with the original MarkDecorator's content updated with the arguments
302
- passed to this call.
300
+ 3. When called in any other case, it returns a new `` MarkDecorator``
301
+ instance with the original `` MarkDecorator`` 's content updated with
302
+ the arguments passed to this call.
303
303
304
- Note: The rules above prevent MarkDecorators from storing only a single
305
- function or class reference as their positional argument with no
304
+ Note: The rules above prevent a ``MarkDecorator`` from storing only a
305
+ single function or class reference as its positional argument with no
306
306
additional keyword or positional arguments. You can work around this by
307
307
using `with_args()`.
308
308
"""
309
309
310
- mark = attr .ib (type = Mark , validator = attr .validators .instance_of (Mark ))
310
+ mark : Mark
311
+
312
+ def __init__ (self , mark : Mark , * , _ispytest : bool = False ) -> None :
313
+ """:meta private:"""
314
+ check_ispytest (_ispytest )
315
+ self .mark = mark
311
316
312
317
@property
313
318
def name (self ) -> str :
@@ -326,6 +331,7 @@ def kwargs(self) -> Mapping[str, Any]:
326
331
327
332
@property
328
333
def markname (self ) -> str :
334
+ """:meta private:"""
329
335
return self .name # for backward-compat (2.4.1 had this attr)
330
336
331
337
def __repr__ (self ) -> str :
@@ -336,17 +342,15 @@ def with_args(self, *args: object, **kwargs: object) -> "MarkDecorator":
336
342
337
343
Unlike calling the MarkDecorator, with_args() can be used even
338
344
if the sole argument is a callable/class.
339
-
340
- :rtype: MarkDecorator
341
345
"""
342
346
mark = Mark (self .name , args , kwargs , _ispytest = True )
343
- return self . __class__ (self .mark .combined_with (mark ))
347
+ return MarkDecorator (self .mark .combined_with (mark ), _ispytest = True )
344
348
345
349
# Type ignored because the overloads overlap with an incompatible
346
350
# return type. Not much we can do about that. Thankfully mypy picks
347
351
# the first match so it works out even if we break the rules.
348
352
@overload
349
- def __call__ (self , arg : _Markable ) -> _Markable : # type: ignore[misc]
353
+ def __call__ (self , arg : Markable ) -> Markable : # type: ignore[misc]
350
354
pass
351
355
352
356
@overload
@@ -405,7 +409,7 @@ def store_mark(obj, mark: Mark) -> None:
405
409
406
410
class _SkipMarkDecorator (MarkDecorator ):
407
411
@overload # type: ignore[override,misc]
408
- def __call__ (self , arg : _Markable ) -> _Markable :
412
+ def __call__ (self , arg : Markable ) -> Markable :
409
413
...
410
414
411
415
@overload
@@ -423,7 +427,7 @@ def __call__( # type: ignore[override]
423
427
424
428
class _XfailMarkDecorator (MarkDecorator ):
425
429
@overload # type: ignore[override,misc]
426
- def __call__ (self , arg : _Markable ) -> _Markable :
430
+ def __call__ (self , arg : Markable ) -> Markable :
427
431
...
428
432
429
433
@overload
@@ -534,7 +538,7 @@ def __getattr__(self, name: str) -> MarkDecorator:
534
538
2 ,
535
539
)
536
540
537
- return MarkDecorator (Mark (name , (), {}, _ispytest = True ))
541
+ return MarkDecorator (Mark (name , (), {}, _ispytest = True ), _ispytest = True )
538
542
539
543
540
544
MARK_GEN = MarkGenerator ()
0 commit comments