Skip to content

Commit

Permalink
Extend SubRequest with param_key
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tobias Deiminger committed Dec 16, 2021
1 parent 11610c0 commit 0bebc76
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import warnings
from collections import defaultdict
from collections import deque
from collections.abc import Hashable
from contextlib import suppress
from pathlib import Path
from types import TracebackType
Expand Down Expand Up @@ -601,6 +602,7 @@ def _compute_fixture_value(self, fixturedef: "FixtureDef[object]") -> None:
except (AttributeError, ValueError):
param = NOTSET
param_index = 0
param_key = ""
has_params = fixturedef.params is not None
fixtures_not_supported = getattr(funcitem, "nofuncargs", False)
if has_params and fixtures_not_supported:
Expand Down Expand Up @@ -640,13 +642,14 @@ def _compute_fixture_value(self, fixturedef: "FixtureDef[object]") -> None:
fail(msg, pytrace=False)
else:
param_index = funcitem.callspec.indices[argname]
param_key = funcitem.callspec.param_keys[argname]
# If a parametrize invocation set a scope it will override
# the static scope defined with the fixture function.
with suppress(KeyError):
scope = funcitem.callspec._arg2scope[argname]

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.
Expand Down Expand Up @@ -731,6 +734,7 @@ def __init__(
scope: Scope,
param: Any,
param_index: int,
param_key: Hashable,
fixturedef: "FixtureDef[object]",
*,
_ispytest: bool = False,
Expand All @@ -741,6 +745,7 @@ def __init__(
if param is not NOTSET:
self.param = param
self.param_index = param_index
self.param_key = param_key
self._scope = scope
self._fixturedef = fixturedef
self._pyfuncitem = request._pyfuncitem
Expand Down

0 comments on commit 0bebc76

Please sign in to comment.