Skip to content

Commit 273ceec

Browse files
committed
set unique fixtureinfo if it was changed from params marks
1 parent 36e52be commit 273ceec

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/_pytest/compat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ def getfuncargnames(
163163
and not isinstance(
164164
inspect.getattr_static(cls, name, default=None), staticmethod
165165
)
166+
and not hasattr(function, "__self__")
166167
):
167168
arg_names = arg_names[1:]
168169
# Remove any names that will be replaced with mocks.

src/_pytest/python.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -504,26 +504,14 @@ def _genfunctions(self, name: str, funcobj) -> Iterator["Function"]:
504504

505505
for callspec in metafunc._calls:
506506
subname = f"{name}[{callspec.id}]"
507-
node = Function.from_parent(
507+
yield Function.from_parent(
508508
self,
509509
name=subname,
510510
callspec=callspec,
511511
fixtureinfo=fixtureinfo,
512512
keywords={callspec.id: True},
513513
originalname=name,
514514
)
515-
# if usefixtures is added via a parameter, then there will be
516-
# fixtures missing from the node.fixturenames
517-
callspec_usefixtures = tuple(
518-
arg
519-
for mark in node.iter_markers(name="usefixtures")
520-
for arg in mark.args
521-
if arg not in node.fixturenames
522-
)
523-
if callspec_usefixtures:
524-
# node.fixturenames must be unique for this parameter
525-
node.fixturenames = [*node.fixturenames, *callspec_usefixtures]
526-
yield node
527515

528516

529517
def importtestmodule(
@@ -1759,10 +1747,14 @@ def __init__(
17591747
if keywords:
17601748
self.keywords.update(keywords)
17611749

1750+
fixtureinfo_ = self.session._fixturemanager.getfixtureinfo(
1751+
self, self.obj, self.cls, funcargs=True
1752+
)
17621753
if fixtureinfo is None:
1763-
fixtureinfo = self.session._fixturemanager.getfixtureinfo(
1764-
self, self.obj, self.cls, funcargs=True
1765-
)
1754+
fixtureinfo = fixtureinfo_
1755+
elif set(fixtureinfo_.names_closure) != set(fixtureinfo.names_closure):
1756+
fixtureinfo_.name2fixturedefs.update(fixtureinfo.name2fixturedefs)
1757+
fixtureinfo = fixtureinfo_
17661758
self._fixtureinfo: FuncFixtureInfo = fixtureinfo
17671759
self.fixturenames = fixtureinfo.names_closure
17681760
self._initrequest()

0 commit comments

Comments
 (0)