7
7
import time
8
8
import traceback
9
9
from enum import Enum
10
- from typing import Dict , Literal , Optional , overload , TYPE_CHECKING , Union
10
+ from typing import Callable , cast , Dict , Literal , Optional , overload , TYPE_CHECKING , TypeVar , Union
11
11
from uuid import UUID
12
12
13
13
import pytest
17
17
if TYPE_CHECKING :
18
18
import lib .host
19
19
20
+ T = TypeVar ("T" )
21
+
20
22
class PackageManagerEnum (Enum ):
21
23
UNKNOWN = 1
22
24
RPM = 2
@@ -67,7 +69,7 @@ def expand_scope_relative_nodeid(scoped_nodeid, scope, ref_nodeid):
67
69
logging .debug ("scope: %r base: %r relative: %r" , scope , base , scoped_nodeid )
68
70
return "::" .join (itertools .chain (base , (scoped_nodeid ,)))
69
71
70
- def callable_marker (value , request ) :
72
+ def callable_marker (value : Union [ T , Callable [..., T ]], request : pytest . FixtureRequest ) -> T :
71
73
"""
72
74
Process value optionally generated by fixture-dependent callable.
73
75
@@ -83,8 +85,12 @@ def callable_marker(value, request):
83
85
for arg_name in inspect .getfullargspec (value ).args }
84
86
except pytest .FixtureLookupError as e :
85
87
raise RuntimeError ("fixture in mapping not found on test" ) from e
86
- value = value (** params )
87
- return value
88
+ # callable ensures the value is of type Callable[..., object], which is not enough in that case
89
+ # we can trust the static checker though, and thus use cast
90
+ fn = cast (Callable [..., T ], value )
91
+ return fn (** params )
92
+ else :
93
+ return value
88
94
89
95
def wait_for (fn , msg = None , timeout_secs = 2 * 60 , retry_delay_secs = 2 , invert = False ):
90
96
if msg is not None :
0 commit comments