Skip to content

Commit 372c17e

Browse files
committed
fixtures: avoid FixtureDef <-> FixtureManager reference cycle
There is no need to store the FixtureManager on each FixtureDef.
1 parent 97dfc34 commit 372c17e

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/_pytest/fixtures.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ class FixtureDef(Generic[FixtureValue]):
970970

971971
def __init__(
972972
self,
973-
fixturemanager: "FixtureManager",
973+
config: Config,
974974
baseid: Optional[str],
975975
argname: str,
976976
func: "_FixtureFunc[FixtureValue]",
@@ -984,7 +984,6 @@ def __init__(
984984
_ispytest: bool = False,
985985
) -> None:
986986
check_ispytest(_ispytest)
987-
self._fixturemanager = fixturemanager
988987
# The "base" node ID for the fixture.
989988
#
990989
# This is a node ID prefix. A fixture is only available to a node (e.g.
@@ -1010,7 +1009,7 @@ def __init__(
10101009
if scope is None:
10111010
scope = Scope.Function
10121011
elif callable(scope):
1013-
scope = _eval_scope_callable(scope, argname, fixturemanager.config)
1012+
scope = _eval_scope_callable(scope, argname, config)
10141013
if isinstance(scope, str):
10151014
scope = Scope.from_user(
10161015
scope, descr=f"Fixture '{func.__name__}'", where=baseid
@@ -1657,7 +1656,7 @@ def _register_fixture(
16571656
Set this if this is a unittest fixture.
16581657
"""
16591658
fixture_def = FixtureDef(
1660-
fixturemanager=self,
1659+
config=self.config,
16611660
baseid=nodeid,
16621661
argname=name,
16631662
func=func,

src/_pytest/python.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ def parametrize(
13231323
fixturedef = name2pseudofixturedef[argname]
13241324
else:
13251325
fixturedef = FixtureDef(
1326-
fixturemanager=self.definition.session._fixturemanager,
1326+
config=self.config,
13271327
baseid="",
13281328
argname=argname,
13291329
func=get_direct_param_fixture_func,

src/_pytest/setuponly.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,23 @@ def pytest_fixture_setup(
4747
else:
4848
param = request.param
4949
fixturedef.cached_param = param # type: ignore[attr-defined]
50-
_show_fixture_action(fixturedef, "SETUP")
50+
_show_fixture_action(fixturedef, request.config, "SETUP")
5151

5252

53-
def pytest_fixture_post_finalizer(fixturedef: FixtureDef[object]) -> None:
53+
def pytest_fixture_post_finalizer(
54+
fixturedef: FixtureDef[object], request: SubRequest
55+
) -> None:
5456
if fixturedef.cached_result is not None:
55-
config = fixturedef._fixturemanager.config
57+
config = request.config
5658
if config.option.setupshow:
57-
_show_fixture_action(fixturedef, "TEARDOWN")
59+
_show_fixture_action(fixturedef, request.config, "TEARDOWN")
5860
if hasattr(fixturedef, "cached_param"):
5961
del fixturedef.cached_param # type: ignore[attr-defined]
6062

6163

62-
def _show_fixture_action(fixturedef: FixtureDef[object], msg: str) -> None:
63-
config = fixturedef._fixturemanager.config
64+
def _show_fixture_action(
65+
fixturedef: FixtureDef[object], config: Config, msg: str
66+
) -> None:
6467
capman = config.pluginmanager.getplugin("capturemanager")
6568
if capman:
6669
capman.suspend_global_capture()

0 commit comments

Comments
 (0)