Skip to content

Commit 9749d28

Browse files
committed
Revert FixtureDef to a single argument
1 parent af0d67a commit 9749d28

File tree

6 files changed

+36
-41
lines changed

6 files changed

+36
-41
lines changed

Diff for: src/_pytest/fixtures.py

+25-27
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def pytest_sessionstart(session: Session) -> None:
131131

132132
def get_scope_package(
133133
node: nodes.Item,
134-
fixturedef: FixtureDef[Any, object],
134+
fixturedef: FixtureDef[object],
135135
) -> nodes.Node | None:
136136
from _pytest.python import Package
137137

@@ -328,7 +328,7 @@ class FuncFixtureInfo:
328328
# matching the name which are applicable to this function.
329329
# There may be multiple overriding fixtures with the same name. The
330330
# sequence is ordered from furthest to closes to the function.
331-
name2fixturedefs: dict[str, Sequence[FixtureDef[Any, Any]]]
331+
name2fixturedefs: dict[str, Sequence[FixtureDef[Any]]]
332332

333333
def prune_dependency_tree(self) -> None:
334334
"""Recompute names_closure from initialnames and name2fixturedefs.
@@ -369,8 +369,8 @@ def __init__(
369369
self,
370370
pyfuncitem: Function,
371371
fixturename: str | None,
372-
arg2fixturedefs: dict[str, Sequence[FixtureDef[Any, Any]]],
373-
fixture_defs: dict[str, FixtureDef[Any, Any]],
372+
arg2fixturedefs: dict[str, Sequence[FixtureDef[Any]]],
373+
fixture_defs: dict[str, FixtureDef[Any]],
374374
*,
375375
_ispytest: bool = False,
376376
) -> None:
@@ -413,7 +413,7 @@ def scope(self) -> _ScopeName:
413413
@abc.abstractmethod
414414
def _check_scope(
415415
self,
416-
requested_fixturedef: FixtureDef[Any, object] | PseudoFixtureDef[object],
416+
requested_fixturedef: FixtureDef[object] | PseudoFixtureDef[object],
417417
requested_scope: Scope,
418418
) -> None:
419419
raise NotImplementedError()
@@ -554,7 +554,7 @@ def _iter_chain(self) -> Iterator[SubRequest]:
554554

555555
def _get_active_fixturedef(
556556
self, argname: str
557-
) -> FixtureDef[Any, object] | PseudoFixtureDef[object]:
557+
) -> FixtureDef[object] | PseudoFixtureDef[object]:
558558
if argname == "request":
559559
cached_result = (self, [0], None)
560560
return PseudoFixtureDef(cached_result, Scope.Function)
@@ -626,9 +626,7 @@ def _get_active_fixturedef(
626626
self._fixture_defs[argname] = fixturedef
627627
return fixturedef
628628

629-
def _check_fixturedef_without_param(
630-
self, fixturedef: FixtureDef[Any, object]
631-
) -> None:
629+
def _check_fixturedef_without_param(self, fixturedef: FixtureDef[object]) -> None:
632630
"""Check that this request is allowed to execute this fixturedef without
633631
a param."""
634632
funcitem = self._pyfuncitem
@@ -661,7 +659,7 @@ def _check_fixturedef_without_param(
661659
)
662660
fail(msg, pytrace=False)
663661

664-
def _get_fixturestack(self) -> list[FixtureDef[Any, Any]]:
662+
def _get_fixturestack(self) -> list[FixtureDef[Any]]:
665663
values = [request._fixturedef for request in self._iter_chain()]
666664
values.reverse()
667665
return values
@@ -686,7 +684,7 @@ def _scope(self) -> Scope:
686684

687685
def _check_scope(
688686
self,
689-
requested_fixturedef: FixtureDef[Any, object] | PseudoFixtureDef[object],
687+
requested_fixturedef: FixtureDef[object] | PseudoFixtureDef[object],
690688
requested_scope: Scope,
691689
) -> None:
692690
# TopRequest always has function scope so always valid.
@@ -720,7 +718,7 @@ def __init__(
720718
scope: Scope,
721719
param: Any,
722720
param_index: int,
723-
fixturedef: FixtureDef[Any, object],
721+
fixturedef: FixtureDef[object],
724722
*,
725723
_ispytest: bool = False,
726724
) -> None:
@@ -733,7 +731,7 @@ def __init__(
733731
)
734732
self._parent_request: Final[FixtureRequest] = request
735733
self._scope_field: Final = scope
736-
self._fixturedef: Final[FixtureDef[Any, object]] = fixturedef
734+
self._fixturedef: Final[FixtureDef[object]] = fixturedef
737735
if param is not NOTSET:
738736
self.param = param
739737
self.param_index: Final = param_index
@@ -763,7 +761,7 @@ def node(self):
763761

764762
def _check_scope(
765763
self,
766-
requested_fixturedef: FixtureDef[Any, object] | PseudoFixtureDef[object],
764+
requested_fixturedef: FixtureDef[object] | PseudoFixtureDef[object],
767765
requested_scope: Scope,
768766
) -> None:
769767
if isinstance(requested_fixturedef, PseudoFixtureDef):
@@ -784,7 +782,7 @@ def _check_scope(
784782
pytrace=False,
785783
)
786784

787-
def _format_fixturedef_line(self, fixturedef: FixtureDef[Any, object]) -> str:
785+
def _format_fixturedef_line(self, fixturedef: FixtureDef[object]) -> str:
788786
factory = fixturedef.func
789787
path, lineno = getfslineno(factory)
790788
if isinstance(path, Path):
@@ -959,7 +957,7 @@ def _eval_scope_callable(
959957

960958

961959
@final
962-
class FixtureDef(Generic[FixtureParams, FixtureValue]):
960+
class FixtureDef(Generic[FixtureValue]):
963961
"""A container for a fixture definition.
964962
965963
This is a generic class parametrized on the parameters that a fixture function receives and its return value.
@@ -973,7 +971,7 @@ def __init__(
973971
config: Config,
974972
baseid: str | None,
975973
argname: str,
976-
func: _FixtureFunc[FixtureParams, FixtureValue],
974+
func: _FixtureFunc[Any, FixtureValue],
977975
scope: Scope | _ScopeName | Callable[[str, Config], _ScopeName] | None,
978976
params: Sequence[object] | None,
979977
ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None,
@@ -1128,8 +1126,8 @@ def __repr__(self) -> str:
11281126

11291127

11301128
def resolve_fixture_function(
1131-
fixturedef: FixtureDef[FixtureParams, FixtureValue], request: FixtureRequest
1132-
) -> _FixtureFunc[FixtureParams, FixtureValue]:
1129+
fixturedef: FixtureDef[FixtureValue], request: FixtureRequest
1130+
) -> _FixtureFunc[Any, FixtureValue]:
11331131
"""Get the actual callable that can be called to obtain the fixture
11341132
value."""
11351133
fixturefunc = fixturedef.func
@@ -1152,7 +1150,7 @@ def resolve_fixture_function(
11521150

11531151

11541152
def pytest_fixture_setup(
1155-
fixturedef: FixtureDef[FixtureParams, FixtureValue], request: SubRequest
1153+
fixturedef: FixtureDef[FixtureValue], request: SubRequest
11561154
) -> FixtureValue:
11571155
"""Execution of fixture setup."""
11581156
kwargs = {}
@@ -1525,7 +1523,7 @@ def __init__(self, session: Session) -> None:
15251523
# suite/plugins defined with this name. Populated by parsefactories().
15261524
# TODO: The order of the FixtureDefs list of each arg is significant,
15271525
# explain.
1528-
self._arg2fixturedefs: Final[dict[str, list[FixtureDef[Any, Any]]]] = {}
1526+
self._arg2fixturedefs: Final[dict[str, list[FixtureDef[Any]]]] = {}
15291527
self._holderobjseen: Final[set[object]] = set()
15301528
# A mapping from a nodeid to a list of autouse fixtures it defines.
15311529
self._nodeid_autousenames: Final[dict[str, list[str]]] = {
@@ -1616,7 +1614,7 @@ def getfixtureclosure(
16161614
parentnode: nodes.Node,
16171615
initialnames: tuple[str, ...],
16181616
ignore_args: AbstractSet[str],
1619-
) -> tuple[list[str], dict[str, Sequence[FixtureDef[Any, Any]]]]:
1617+
) -> tuple[list[str], dict[str, Sequence[FixtureDef[Any]]]]:
16201618
# Collect the closure of all fixtures, starting with the given
16211619
# fixturenames as the initial set. As we have to visit all
16221620
# factory definitions anyway, we also return an arg2fixturedefs
@@ -1626,7 +1624,7 @@ def getfixtureclosure(
16261624

16271625
fixturenames_closure = list(initialnames)
16281626

1629-
arg2fixturedefs: dict[str, Sequence[FixtureDef[Any, Any]]] = {}
1627+
arg2fixturedefs: dict[str, Sequence[FixtureDef[Any]]] = {}
16301628
lastlen = -1
16311629
while lastlen != len(fixturenames_closure):
16321630
lastlen = len(fixturenames_closure)
@@ -1841,7 +1839,7 @@ def parsefactories(
18411839

18421840
def getfixturedefs(
18431841
self, argname: str, node: nodes.Node
1844-
) -> Sequence[FixtureDef[Any, Any]] | None:
1842+
) -> Sequence[FixtureDef[Any]] | None:
18451843
"""Get FixtureDefs for a fixture name which are applicable
18461844
to a given node.
18471845
@@ -1860,8 +1858,8 @@ def getfixturedefs(
18601858
return tuple(self._matchfactories(fixturedefs, node))
18611859

18621860
def _matchfactories(
1863-
self, fixturedefs: Iterable[FixtureDef[Any, Any]], node: nodes.Node
1864-
) -> Iterator[FixtureDef[Any, Any]]:
1861+
self, fixturedefs: Iterable[FixtureDef[Any]], node: nodes.Node
1862+
) -> Iterator[FixtureDef[Any]]:
18651863
parentnodeids = {n.nodeid for n in node.iter_parents()}
18661864
for fixturedef in fixturedefs:
18671865
if fixturedef.baseid in parentnodeids:
@@ -1898,7 +1896,7 @@ def get_best_relpath(func) -> str:
18981896
loc = getlocation(func, invocation_dir)
18991897
return bestrelpath(invocation_dir, Path(loc))
19001898

1901-
def write_fixture(fixture_def: FixtureDef[Any, object]) -> None:
1899+
def write_fixture(fixture_def: FixtureDef[object]) -> None:
19021900
argname = fixture_def.argname
19031901
if verbose <= 0 and argname.startswith("_"):
19041902
return

Diff for: src/_pytest/hookspec.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ def pytest_report_from_serializable(
866866

867867
@hookspec(firstresult=True)
868868
def pytest_fixture_setup(
869-
fixturedef: FixtureDef[Any, Any], request: SubRequest
869+
fixturedef: FixtureDef[Any], request: SubRequest
870870
) -> object | None:
871871
"""Perform fixture setup execution.
872872
@@ -894,7 +894,7 @@ def pytest_fixture_setup(
894894

895895

896896
def pytest_fixture_post_finalizer(
897-
fixturedef: FixtureDef[Any, Any], request: SubRequest
897+
fixturedef: FixtureDef[Any], request: SubRequest
898898
) -> None:
899899
"""Called after fixture teardown, but before the cache is cleared, so
900900
the fixture result ``fixturedef.cached_result`` is still available (not

Diff for: src/_pytest/python.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ def get_direct_param_fixture_func(request: FixtureRequest) -> Any:
10851085

10861086

10871087
# Used for storing pseudo fixturedefs for direct parametrization.
1088-
name2pseudofixturedef_key = StashKey[dict[str, FixtureDef[Any, Any]]]()
1088+
name2pseudofixturedef_key = StashKey[dict[str, FixtureDef[Any]]]()
10891089

10901090

10911091
@final
@@ -1271,7 +1271,7 @@ def parametrize(
12711271
if node is None:
12721272
name2pseudofixturedef = None
12731273
else:
1274-
default: dict[str, FixtureDef[Any, Any]] = {}
1274+
default: dict[str, FixtureDef[Any]] = {}
12751275
name2pseudofixturedef = node.stash.setdefault(
12761276
name2pseudofixturedef_key, default
12771277
)
@@ -1458,7 +1458,7 @@ def _recompute_direct_params_indices(self) -> None:
14581458

14591459
def _find_parametrized_scope(
14601460
argnames: Sequence[str],
1461-
arg2fixturedefs: Mapping[str, Sequence[fixtures.FixtureDef[Any, object]]],
1461+
arg2fixturedefs: Mapping[str, Sequence[fixtures.FixtureDef[object]]],
14621462
indirect: bool | Sequence[str],
14631463
) -> Scope:
14641464
"""Find the most appropriate scope for a parametrized call based on its arguments.

Diff for: src/_pytest/setuponly.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
from collections.abc import Generator
4-
from typing import Any
54

65
from _pytest._io.saferepr import saferepr
76
from _pytest.config import Config
@@ -31,7 +30,7 @@ def pytest_addoption(parser: Parser) -> None:
3130

3231
@pytest.hookimpl(wrapper=True)
3332
def pytest_fixture_setup(
34-
fixturedef: FixtureDef[Any, object], request: SubRequest
33+
fixturedef: FixtureDef[object], request: SubRequest
3534
) -> Generator[None, object, object]:
3635
try:
3736
return (yield)
@@ -52,7 +51,7 @@ def pytest_fixture_setup(
5251

5352

5453
def pytest_fixture_post_finalizer(
55-
fixturedef: FixtureDef[Any, object], request: SubRequest
54+
fixturedef: FixtureDef[object], request: SubRequest
5655
) -> None:
5756
if fixturedef.cached_result is not None:
5857
config = request.config
@@ -63,7 +62,7 @@ def pytest_fixture_post_finalizer(
6362

6463

6564
def _show_fixture_action(
66-
fixturedef: FixtureDef[Any, object], config: Config, msg: str
65+
fixturedef: FixtureDef[object], config: Config, msg: str
6766
) -> None:
6867
capman = config.pluginmanager.getplugin("capturemanager")
6968
if capman:

Diff for: src/_pytest/setupplan.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
from typing import Any
4-
53
from _pytest.config import Config
64
from _pytest.config import ExitCode
75
from _pytest.config.argparsing import Parser
@@ -23,7 +21,7 @@ def pytest_addoption(parser: Parser) -> None:
2321

2422
@pytest.hookimpl(tryfirst=True)
2523
def pytest_fixture_setup(
26-
fixturedef: FixtureDef[Any, object], request: SubRequest
24+
fixturedef: FixtureDef[object], request: SubRequest
2725
) -> object | None:
2826
# Will return a dummy fixture if the setuponly option is provided.
2927
if request.config.option.setupplan:

Diff for: testing/python/metafunc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def Metafunc(self, func, config=None) -> python.Metafunc:
3232
# on the funcarg level, so we don't need a full blown
3333
# initialization.
3434
class FuncFixtureInfoMock:
35-
name2fixturedefs: dict[str, list[fixtures.FixtureDef[Any, object]]] = {}
35+
name2fixturedefs: dict[str, list[fixtures.FixtureDef[object]]] = {}
3636

3737
def __init__(self, names):
3838
self.names_closure = names
@@ -153,7 +153,7 @@ class DummyFixtureDef:
153153
_scope: Scope
154154

155155
fixtures_defs = cast(
156-
dict[str, Sequence[fixtures.FixtureDef[Any, object]]],
156+
dict[str, Sequence[fixtures.FixtureDef[object]]],
157157
dict(
158158
session_fix=[DummyFixtureDef(Scope.Session)],
159159
package_fix=[DummyFixtureDef(Scope.Package)],

0 commit comments

Comments
 (0)