File tree Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -348,18 +348,21 @@ def _get_legacy_hook_marks(
348
348
hook_type : str ,
349
349
opt_names : Tuple [str , ...],
350
350
) -> Dict [str , bool ]:
351
- known_marks = {m .name for m in getattr (method , "pytestmark" , [])}
352
- must_warn = False
353
- opts = {}
351
+ known_marks : set [ str ] = {m .name for m in getattr (method , "pytestmark" , [])}
352
+ must_warn : list [ str ] = []
353
+ opts : dict [ str , bool ] = {}
354
354
for opt_name in opt_names :
355
+ opt_attr = getattr (method , opt_name , AttributeError )
356
+ if opt_attr is not AttributeError :
357
+ must_warn .append (f"{ opt_name } ={ opt_attr } " )
358
+ elif opt_name in known_marks :
359
+ must_warn .append (f"{ opt_name } =True" )
355
360
if hasattr (method , opt_name ) or opt_name in known_marks :
356
361
opts [opt_name ] = True
357
- must_warn = True
358
362
else :
359
363
opts [opt_name ] = False
360
364
if must_warn :
361
-
362
- hook_opts = ", " .join (f"{ name } =True" for name , val in opts .items () if val )
365
+ hook_opts = ", " .join (must_warn )
363
366
message = _pytest .deprecated .HOOK_LEGACY_MARKING .format (
364
367
type = hook_type ,
365
368
fullname = method .__qualname__ , # type: ignore
Original file line number Diff line number Diff line change @@ -29,11 +29,11 @@ class DeprecatedHookMarkerSpec:
29
29
def pytest_bad_hook (self ):
30
30
pass
31
31
32
- pytest_bad_hook .historic = True # type: ignore[attr-defined]
32
+ pytest_bad_hook .historic = False # type: ignore[attr-defined]
33
33
34
34
with pytest .warns (
35
35
PytestDeprecationWarning ,
36
- match = r"Please use the pytest\.hookspec\(historic=True \) decorator" ,
36
+ match = r"Please use the pytest\.hookspec\(historic=False \) decorator" ,
37
37
) as recorder :
38
38
pm .add_hookspecs (DeprecatedHookMarkerSpec )
39
39
(record ,) = recorder
You can’t perform that action at this time.
0 commit comments