79
79
80
80
81
81
# The value of the fixture -- return/yield of the fixture function (type variable).
82
- _FixtureValue = TypeVar ("_FixtureValue " )
82
+ FixtureValue = TypeVar ("FixtureValue " )
83
83
# The type of the fixture function (type variable).
84
- _FixtureFunction = TypeVar ("_FixtureFunction " , bound = Callable [..., object ])
84
+ FixtureFunction = TypeVar ("FixtureFunction " , bound = Callable [..., object ])
85
85
# The type of a fixture function (type alias generic in fixture value).
86
86
_FixtureFunc = Union [
87
- Callable [..., _FixtureValue ], Callable [..., Generator [_FixtureValue , None , None ]]
87
+ Callable [..., FixtureValue ], Callable [..., Generator [FixtureValue , None , None ]]
88
88
]
89
89
# The type of FixtureDef.cached_result (type alias generic in fixture value).
90
90
_FixtureCachedResult = Union [
91
91
Tuple [
92
92
# The result.
93
- _FixtureValue ,
93
+ FixtureValue ,
94
94
# Cache key.
95
95
object ,
96
96
None ,
106
106
107
107
108
108
@attr .s (frozen = True )
109
- class PseudoFixtureDef (Generic [_FixtureValue ]):
110
- cached_result = attr .ib (type = "_FixtureCachedResult[_FixtureValue ]" )
109
+ class PseudoFixtureDef (Generic [FixtureValue ]):
110
+ cached_result = attr .ib (type = "_FixtureCachedResult[FixtureValue ]" )
111
111
scope = attr .ib (type = "_Scope" )
112
112
113
113
@@ -928,11 +928,11 @@ def fail_fixturefunc(fixturefunc, msg: str) -> "NoReturn":
928
928
929
929
930
930
def call_fixture_func (
931
- fixturefunc : "_FixtureFunc[_FixtureValue ]" , request : FixtureRequest , kwargs
932
- ) -> _FixtureValue :
931
+ fixturefunc : "_FixtureFunc[FixtureValue ]" , request : FixtureRequest , kwargs
932
+ ) -> FixtureValue :
933
933
if is_generator (fixturefunc ):
934
934
fixturefunc = cast (
935
- Callable [..., Generator [_FixtureValue , None , None ]], fixturefunc
935
+ Callable [..., Generator [FixtureValue , None , None ]], fixturefunc
936
936
)
937
937
generator = fixturefunc (** kwargs )
938
938
try :
@@ -942,7 +942,7 @@ def call_fixture_func(
942
942
finalizer = functools .partial (_teardown_yield_fixture , fixturefunc , generator )
943
943
request .addfinalizer (finalizer )
944
944
else :
945
- fixturefunc = cast (Callable [..., _FixtureValue ], fixturefunc )
945
+ fixturefunc = cast (Callable [..., FixtureValue ], fixturefunc )
946
946
fixture_result = fixturefunc (** kwargs )
947
947
return fixture_result
948
948
@@ -985,15 +985,15 @@ def _eval_scope_callable(
985
985
986
986
987
987
@final
988
- class FixtureDef (Generic [_FixtureValue ]):
988
+ class FixtureDef (Generic [FixtureValue ]):
989
989
"""A container for a factory definition."""
990
990
991
991
def __init__ (
992
992
self ,
993
993
fixturemanager : "FixtureManager" ,
994
994
baseid : Optional [str ],
995
995
argname : str ,
996
- func : "_FixtureFunc[_FixtureValue ]" ,
996
+ func : "_FixtureFunc[FixtureValue ]" ,
997
997
scope : "Union[_Scope, Callable[[str, Config], _Scope]]" ,
998
998
params : Optional [Sequence [object ]],
999
999
unittest : bool = False ,
@@ -1026,7 +1026,7 @@ def __init__(
1026
1026
)
1027
1027
self .unittest = unittest
1028
1028
self .ids = ids
1029
- self .cached_result : Optional [_FixtureCachedResult [_FixtureValue ]] = None
1029
+ self .cached_result : Optional [_FixtureCachedResult [FixtureValue ]] = None
1030
1030
self ._finalizers : List [Callable [[], object ]] = []
1031
1031
1032
1032
def addfinalizer (self , finalizer : Callable [[], object ]) -> None :
@@ -1055,7 +1055,7 @@ def finish(self, request: SubRequest) -> None:
1055
1055
self .cached_result = None
1056
1056
self ._finalizers = []
1057
1057
1058
- def execute (self , request : SubRequest ) -> _FixtureValue :
1058
+ def execute (self , request : SubRequest ) -> FixtureValue :
1059
1059
# Get required arguments and register our own finish()
1060
1060
# with their finalization.
1061
1061
for argname in self .argnames :
@@ -1096,8 +1096,8 @@ def __repr__(self) -> str:
1096
1096
1097
1097
1098
1098
def resolve_fixture_function (
1099
- fixturedef : FixtureDef [_FixtureValue ], request : FixtureRequest
1100
- ) -> "_FixtureFunc[_FixtureValue ]" :
1099
+ fixturedef : FixtureDef [FixtureValue ], request : FixtureRequest
1100
+ ) -> "_FixtureFunc[FixtureValue ]" :
1101
1101
"""Get the actual callable that can be called to obtain the fixture
1102
1102
value, dealing with unittest-specific instances and bound methods."""
1103
1103
fixturefunc = fixturedef .func
@@ -1123,8 +1123,8 @@ def resolve_fixture_function(
1123
1123
1124
1124
1125
1125
def pytest_fixture_setup (
1126
- fixturedef : FixtureDef [_FixtureValue ], request : SubRequest
1127
- ) -> _FixtureValue :
1126
+ fixturedef : FixtureDef [FixtureValue ], request : SubRequest
1127
+ ) -> FixtureValue :
1128
1128
"""Execution of fixture setup."""
1129
1129
kwargs = {}
1130
1130
for argname in fixturedef .argnames :
@@ -1174,9 +1174,9 @@ def _params_converter(
1174
1174
1175
1175
1176
1176
def wrap_function_to_error_out_if_called_directly (
1177
- function : _FixtureFunction ,
1177
+ function : FixtureFunction ,
1178
1178
fixture_marker : "FixtureFunctionMarker" ,
1179
- ) -> _FixtureFunction :
1179
+ ) -> FixtureFunction :
1180
1180
"""Wrap the given fixture function so we can raise an error about it being called directly,
1181
1181
instead of used as an argument in a test function."""
1182
1182
message = (
@@ -1194,7 +1194,7 @@ def result(*args, **kwargs):
1194
1194
# further than this point and lose useful wrappings like @mock.patch (#3774).
1195
1195
result .__pytest_wrapped__ = _PytestWrapper (function ) # type: ignore[attr-defined]
1196
1196
1197
- return cast (_FixtureFunction , result )
1197
+ return cast (FixtureFunction , result )
1198
1198
1199
1199
1200
1200
@final
@@ -1213,7 +1213,7 @@ class FixtureFunctionMarker:
1213
1213
)
1214
1214
name = attr .ib (type = Optional [str ], default = None )
1215
1215
1216
- def __call__ (self , function : _FixtureFunction ) -> _FixtureFunction :
1216
+ def __call__ (self , function : FixtureFunction ) -> FixtureFunction :
1217
1217
if inspect .isclass (function ):
1218
1218
raise ValueError ("class fixtures not supported (maybe in the future)" )
1219
1219
@@ -1241,7 +1241,7 @@ def __call__(self, function: _FixtureFunction) -> _FixtureFunction:
1241
1241
1242
1242
@overload
1243
1243
def fixture (
1244
- fixture_function : _FixtureFunction ,
1244
+ fixture_function : FixtureFunction ,
1245
1245
* ,
1246
1246
scope : "Union[_Scope, Callable[[str, Config], _Scope]]" = ...,
1247
1247
params : Optional [Iterable [object ]] = ...,
@@ -1253,7 +1253,7 @@ def fixture(
1253
1253
]
1254
1254
] = ...,
1255
1255
name : Optional [str ] = ...,
1256
- ) -> _FixtureFunction :
1256
+ ) -> FixtureFunction :
1257
1257
...
1258
1258
1259
1259
@@ -1276,7 +1276,7 @@ def fixture(
1276
1276
1277
1277
1278
1278
def fixture (
1279
- fixture_function : Optional [_FixtureFunction ] = None ,
1279
+ fixture_function : Optional [FixtureFunction ] = None ,
1280
1280
* ,
1281
1281
scope : "Union[_Scope, Callable[[str, Config], _Scope]]" = "function" ,
1282
1282
params : Optional [Iterable [object ]] = None ,
@@ -1288,7 +1288,7 @@ def fixture(
1288
1288
]
1289
1289
] = None ,
1290
1290
name : Optional [str ] = None ,
1291
- ) -> Union [FixtureFunctionMarker , _FixtureFunction ]:
1291
+ ) -> Union [FixtureFunctionMarker , FixtureFunction ]:
1292
1292
"""Decorator to mark a fixture factory function.
1293
1293
1294
1294
This decorator can be used, with or without parameters, to define a
0 commit comments