@@ -378,21 +378,9 @@ class _EmptyClass: pass # noqa: E701
378
378
# fmt: on
379
379
380
380
381
- def prune_dependency_tree_if_test_is_dynamically_parametrized (metafunc ):
381
+ def check_if_test_is_dynamically_parametrized (metafunc ):
382
382
if metafunc ._calls :
383
- # Dynamic direct parametrization may have shadowed some fixtures
384
- # so make sure we update what the function really needs. Note that
385
- # we didn't need to do this if only indirect dynamic parametrization
386
- # had taken place, but anyway we did it as differentiating between direct
387
- # and indirect requires a dirty hack.
388
- definition = metafunc .definition
389
- fixture_closure = definition .parent .session ._fixturemanager .getfixtureclosure (
390
- definition ,
391
- definition ._fixtureinfo .initialnames ,
392
- definition ._fixtureinfo .name2fixturedefs ,
393
- ignore_args = _get_direct_parametrize_args (definition ) + ["request" ],
394
- )
395
- definition ._fixtureinfo .names_closure [:] = fixture_closure
383
+ setattr (metafunc , "has_dynamic_parametrize" , True )
396
384
397
385
398
386
class PyCollector (PyobjMixin , nodes .Collector ):
@@ -499,7 +487,7 @@ def _genfunctions(self, name: str, funcobj) -> Iterator["Function"]:
499
487
module = module ,
500
488
_ispytest = True ,
501
489
)
502
- methods = [prune_dependency_tree_if_test_is_dynamically_parametrized ]
490
+ methods = [check_if_test_is_dynamically_parametrized ]
503
491
if hasattr (module , "pytest_generate_tests" ):
504
492
methods .append (module .pytest_generate_tests )
505
493
if cls is not None and hasattr (cls , "pytest_generate_tests" ):
@@ -516,6 +504,20 @@ def _genfunctions(self, name: str, funcobj) -> Iterator["Function"]:
516
504
fm = self .session ._fixturemanager
517
505
fixtures .add_funcarg_pseudo_fixture_def (self , metafunc , fm )
518
506
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
+
519
521
for callspec in metafunc ._calls :
520
522
subname = f"{ name } [{ callspec .id } ]"
521
523
yield Function .from_parent (
0 commit comments