Extend SubRequest with param_key
Pick up the value from curent CallSpec2 and assign it to the SubRequest. It's required to make the parameter key accessible in FixtureDef.execute.
This commit is contained in:
parent
a8151fb267
commit
94279c0931
|
@ -5,6 +5,7 @@ import sys
|
||||||
import warnings
|
import warnings
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
from collections.abc import Hashable
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from types import TracebackType
|
from types import TracebackType
|
||||||
|
@ -601,6 +602,7 @@ class FixtureRequest:
|
||||||
except (AttributeError, ValueError):
|
except (AttributeError, ValueError):
|
||||||
param = NOTSET
|
param = NOTSET
|
||||||
param_index = 0
|
param_index = 0
|
||||||
|
param_key = ""
|
||||||
has_params = fixturedef.params is not None
|
has_params = fixturedef.params is not None
|
||||||
fixtures_not_supported = getattr(funcitem, "nofuncargs", False)
|
fixtures_not_supported = getattr(funcitem, "nofuncargs", False)
|
||||||
if has_params and fixtures_not_supported:
|
if has_params and fixtures_not_supported:
|
||||||
|
@ -640,13 +642,14 @@ class FixtureRequest:
|
||||||
fail(msg, pytrace=False)
|
fail(msg, pytrace=False)
|
||||||
else:
|
else:
|
||||||
param_index = funcitem.callspec.indices[argname]
|
param_index = funcitem.callspec.indices[argname]
|
||||||
|
param_key = funcitem.callspec.param_keys[argname]
|
||||||
# If a parametrize invocation set a scope it will override
|
# If a parametrize invocation set a scope it will override
|
||||||
# the static scope defined with the fixture function.
|
# the static scope defined with the fixture function.
|
||||||
with suppress(KeyError):
|
with suppress(KeyError):
|
||||||
scope = funcitem.callspec._arg2scope[argname]
|
scope = funcitem.callspec._arg2scope[argname]
|
||||||
|
|
||||||
subrequest = SubRequest(
|
subrequest = SubRequest(
|
||||||
self, scope, param, param_index, fixturedef, _ispytest=True
|
self, scope, param, param_index, param_key, fixturedef, _ispytest=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check if a higher-level scoped fixture accesses a lower level one.
|
# Check if a higher-level scoped fixture accesses a lower level one.
|
||||||
|
@ -731,6 +734,7 @@ class SubRequest(FixtureRequest):
|
||||||
scope: Scope,
|
scope: Scope,
|
||||||
param: Any,
|
param: Any,
|
||||||
param_index: int,
|
param_index: int,
|
||||||
|
param_key: Hashable,
|
||||||
fixturedef: "FixtureDef[object]",
|
fixturedef: "FixtureDef[object]",
|
||||||
*,
|
*,
|
||||||
_ispytest: bool = False,
|
_ispytest: bool = False,
|
||||||
|
@ -741,6 +745,7 @@ class SubRequest(FixtureRequest):
|
||||||
if param is not NOTSET:
|
if param is not NOTSET:
|
||||||
self.param = param
|
self.param = param
|
||||||
self.param_index = param_index
|
self.param_index = param_index
|
||||||
|
self.param_key = param_key
|
||||||
self._scope = scope
|
self._scope = scope
|
||||||
self._fixturedef = fixturedef
|
self._fixturedef = fixturedef
|
||||||
self._pyfuncitem = request._pyfuncitem
|
self._pyfuncitem = request._pyfuncitem
|
||||||
|
|
Loading…
Reference in New Issue