From 574e0f45d908cd51f81538543e9aedcaeaac6900 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 1 Sep 2023 15:36:41 +0300 Subject: [PATCH] fixtures: avoid using the mildly expensive `fixturenames` property Avoid creating a list copy + 2 sets + a linear search through the list (in the common case). --- src/_pytest/fixtures.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index dee34c348..e692c9489 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -791,7 +791,10 @@ class SubRequest(FixtureRequest): # If the executing fixturedef was not explicitly requested in the argument list (via # getfixturevalue inside the fixture call) then ensure this fixture def will be finished # first. - if fixturedef.argname not in self.fixturenames: + if ( + fixturedef.argname not in self._fixture_defs + and fixturedef.argname not in self._pyfuncitem.fixturenames + ): fixturedef.addfinalizer( functools.partial(self._fixturedef.finish, request=self) )