@@ -381,21 +381,9 @@ class _EmptyClass: pass # noqa: E701
381381# fmt: on
382382
383383
384- def prune_dependency_tree_if_test_is_dynamically_parametrized (metafunc ):
384+ def check_if_test_is_dynamically_parametrized (metafunc ):
385385 if metafunc ._calls :
386- # Dynamic direct parametrization may have shadowed some fixtures
387- # so make sure we update what the function really needs. Note that
388- # we didn't need to do this if only indirect dynamic parametrization
389- # had taken place, but anyway we did it as differentiating between direct
390- # and indirect requires a dirty hack.
391- definition = metafunc .definition
392- fixture_closure = definition .parent .session ._fixturemanager .getfixtureclosure (
393- definition ,
394- definition ._fixtureinfo .initialnames ,
395- definition ._fixtureinfo .name2fixturedefs ,
396- ignore_args = _get_direct_parametrize_args (definition ) + ["request" ],
397- )
398- definition ._fixtureinfo .names_closure [:] = fixture_closure
386+ setattr (metafunc , "has_dynamic_parametrize" , True )
399387
400388
401389class PyCollector (PyobjMixin , nodes .Collector ):
@@ -502,7 +490,7 @@ def _genfunctions(self, name: str, funcobj) -> Iterator["Function"]:
502490 module = module ,
503491 _ispytest = True ,
504492 )
505- methods = [prune_dependency_tree_if_test_is_dynamically_parametrized ]
493+ methods = [check_if_test_is_dynamically_parametrized ]
506494 if hasattr (module , "pytest_generate_tests" ):
507495 methods .append (module .pytest_generate_tests )
508496 if cls is not None and hasattr (cls , "pytest_generate_tests" ):
@@ -516,6 +504,20 @@ def _genfunctions(self, name: str, funcobj) -> Iterator["Function"]:
516504 yield Function .from_parent (self , name = name , fixtureinfo = fixtureinfo )
517505 else :
518506
507+ if hasattr (metafunc , "has_dynamic_parametrize" ):
508+ # add_funcarg_pseudo_fixture_def may have shadowed some fixtures
509+ # due to dynamic direct parametrization so make sure we update
510+ # what the function really needs. Note that we didn't need to do this if
511+ # only indirect dynamic parametrization had taken place, but anyway we did
512+ # it as differentiating between direct and indirect requires a dirty hack.
513+ fixture_closure , _ = fm .getfixtureclosure (
514+ definition ,
515+ fixtureinfo .initialnames ,
516+ fixtureinfo .name2fixturedefs ,
517+ ignore_args = _get_direct_parametrize_args (definition ),
518+ )
519+ fixtureinfo .names_closure [:] = fixture_closure
520+
519521 for callspec in metafunc ._calls :
520522 subname = f"{ name } [{ callspec .id } ]"
521523 yield Function .from_parent (
0 commit comments