@@ -272,3 +272,103 @@ def test_with_redefined_fixture(my_fixture):
272272 ),
273273 )
274274 )
275+
276+
277+ @pytest .mark .parametrize (
278+ ["parent_scope" , "child_scope" ],
279+ list (combinations_with_replacement (fixture_scopes , 2 ))
280+ )
281+ def test_dynamically_called_fixture (allured_testdir , parent_scope , child_scope ):
282+ allured_testdir .testdir .makepyfile ("""
283+ import pytest
284+
285+ @pytest.fixture(scope="{parent_scope}", autouse=True)
286+ def parent_auto_call_fixture():
287+ yield
288+
289+ @pytest.fixture(scope="{child_scope}")
290+ def child_manual_call_fixture():
291+ yield
292+
293+ @pytest.fixture(scope="{parent_scope}")
294+ def parent_dyn_call_fixture():
295+ yield
296+
297+ @pytest.fixture(scope="{child_scope}")
298+ def child_dyn_call_fixture(request):
299+ request.getfixturevalue('parent_dyn_call_fixture')
300+
301+ def test_one(child_manual_call_fixture):
302+ pass
303+
304+ def test_two(request):
305+ request.getfixturevalue('child_dyn_call_fixture')
306+
307+ def test_three(request):
308+ request.getfixturevalue('parent_dyn_call_fixture')
309+ """ .format (parent_scope = parent_scope , child_scope = child_scope ))
310+
311+ allured_testdir .run_with_allure ()
312+
313+ assert_that (allured_testdir .allure_report ,
314+ has_test_case ("test_one" ,
315+ has_container (allured_testdir .allure_report ,
316+ has_before ("parent_auto_call_fixture" ),
317+ has_after ("parent_auto_call_fixture::0" ),
318+ ),
319+ has_container (allured_testdir .allure_report ,
320+ has_before ("child_manual_call_fixture" ),
321+ has_after ("child_manual_call_fixture::0" ),
322+ ),
323+ not_ (has_container (allured_testdir .allure_report ,
324+ has_before ("parent_dyn_call_fixture" ),
325+ has_after ("parent_dyn_call_fixture::0" ),
326+ ),
327+ ),
328+ not_ (has_container (allured_testdir .allure_report ,
329+ has_before ("child_dyn_call_fixture" ),
330+ ),
331+ )
332+ )
333+ )
334+ assert_that (allured_testdir .allure_report ,
335+ has_test_case ("test_two" ,
336+ has_container (allured_testdir .allure_report ,
337+ has_before ("parent_auto_call_fixture" ),
338+ has_after ("parent_auto_call_fixture::0" ),
339+ ),
340+ not_ (has_container (allured_testdir .allure_report ,
341+ has_before ("child_manual_call_fixture" ),
342+ has_after ("child_manual_call_fixture::0" ),
343+ ),
344+ ),
345+ has_container (allured_testdir .allure_report ,
346+ has_before ("parent_dyn_call_fixture" ),
347+ has_after ("parent_dyn_call_fixture::0" ),
348+ ),
349+ has_container (allured_testdir .allure_report ,
350+ has_before ("child_dyn_call_fixture" ),
351+ ),
352+ ),
353+ )
354+ assert_that (allured_testdir .allure_report ,
355+ has_test_case ("test_three" ,
356+ has_container (allured_testdir .allure_report ,
357+ has_before ("parent_auto_call_fixture" ),
358+ has_after ("parent_auto_call_fixture::0" ),
359+ ),
360+ not_ (has_container (allured_testdir .allure_report ,
361+ has_before ("child_manual_call_fixture" ),
362+ has_after ("child_manual_call_fixture::0" ),
363+ ),
364+ ),
365+ has_container (allured_testdir .allure_report ,
366+ has_before ("parent_dyn_call_fixture" ),
367+ has_after ("parent_dyn_call_fixture::0" ),
368+ ),
369+ not_ (has_container (allured_testdir .allure_report ,
370+ has_before ("child_dyn_call_fixture" ),
371+ ),
372+ )
373+ )
374+ )
0 commit comments