Skip to content

Commit c890d8b

Browse files
committed
update fixture tests
1 parent 014fda4 commit c890d8b

File tree

1 file changed

+86
-10
lines changed

1 file changed

+86
-10
lines changed

allure-pytest/test/acceptance/fixture/fixture_test.py

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,25 +274,101 @@ def test_with_redefined_fixture(my_fixture):
274274
)
275275

276276

277-
def test_dynamically_called_fixture(allured_testdir):
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):
278282
allured_testdir.testdir.makepyfile("""
279283
import pytest
280284
281-
@pytest.fixture
282-
def my_fixture():
285+
@pytest.fixture(scope="{parent_scope}", autouse=True)
286+
def parent_auto_call_fixture():
283287
yield
284288
285-
def test_fixture_example(request):
286-
request.getfixturevalue('my_fixture')
287-
""")
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))
288310

289311
allured_testdir.run_with_allure()
290312

291313
assert_that(allured_testdir.allure_report,
292-
has_test_case("test_fixture_example",
314+
has_test_case("test_one",
293315
has_container(allured_testdir.allure_report,
294-
has_before("my_fixture"),
295-
has_after("my_fixture::0"),
316+
has_before("parent_auto_call_fixture"),
317+
has_after("parent_auto_call_fixture::0"),
296318
),
297-
)
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+
)
298374
)

0 commit comments

Comments
 (0)