Skip to content

Commit 774f0c4

Browse files
committed
fixtures: only call instance property once in function
No need to compute the property multiple times.
1 parent 006058f commit 774f0c4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/_pytest/fixtures.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,17 +1101,18 @@ def resolve_fixture_function(
11011101
# The fixture function needs to be bound to the actual
11021102
# request.instance so that code working with "fixturedef" behaves
11031103
# as expected.
1104-
if request.instance is not None:
1104+
instance = request.instance
1105+
if instance is not None:
11051106
# Handle the case where fixture is defined not in a test class, but some other class
11061107
# (for example a plugin class with a fixture), see #2270.
11071108
if hasattr(fixturefunc, "__self__") and not isinstance(
1108-
request.instance,
1109+
instance,
11091110
fixturefunc.__self__.__class__, # type: ignore[union-attr]
11101111
):
11111112
return fixturefunc
11121113
fixturefunc = getimfunc(fixturedef.func)
11131114
if fixturefunc != fixturedef.func:
1114-
fixturefunc = fixturefunc.__get__(request.instance) # type: ignore[union-attr]
1115+
fixturefunc = fixturefunc.__get__(instance) # type: ignore[union-attr]
11151116
return fixturefunc
11161117

11171118

0 commit comments

Comments
 (0)