Skip to content

Commit bc21f4c

Browse files
committed
Adding tests for nested lazy fixtures
1 parent 7ecb049 commit bc21f4c

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

tests/test_lazyfixture.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,91 @@ def test_sorted_by_dependency(params, expected_paths):
580580
])
581581
def test_sorted_argnames(params, fixturenames, expect_keys):
582582
assert list(_sorted_argnames(params, fixturenames)) == expect_keys
583+
584+
585+
def test_lazy_fixtures_with_subfixtures(testdir):
586+
testdir.makepyfile("""
587+
import pytest
588+
589+
@pytest.fixture(params=["a", "A"])
590+
def a(request):
591+
return request.param
592+
593+
@pytest.fixture(params=["b", "B"])
594+
def b(a, request):
595+
return request.param + a
596+
597+
@pytest.fixture
598+
def c(a):
599+
return "c" + a
600+
601+
@pytest.fixture(params=[pytest.lazy_fixture('a'), pytest.lazy_fixture('b'), pytest.lazy_fixture('c')])
602+
def d(request):
603+
return "d" + request.param
604+
605+
@pytest.fixture(params=[pytest.lazy_fixture('a'), pytest.lazy_fixture('d'), ""])
606+
def e(request):
607+
return "e" + request.param
608+
609+
def test_one(d):
610+
assert d in ("da", "dA", "dba", "dbA", "dBa", "dBA", "dca", "dcA")
611+
612+
def test_two(e):
613+
assert e in ("ea", "eA", "eda", "edA", "edba", "edbA", "edBa", "edBA", "edca", "edcA", "e")
614+
""")
615+
reprec = testdir.inline_run('-s', '-v')
616+
reprec.assertoutcome(passed=19)
617+
618+
619+
def test_lazy_fixtures_in_subfixture(testdir):
620+
testdir.makepyfile("""
621+
import pytest
622+
623+
@pytest.fixture
624+
def a():
625+
return "a"
626+
627+
@pytest.fixture
628+
def b():
629+
return "b"
630+
631+
@pytest.fixture(params=[pytest.lazy_fixture('a'), pytest.lazy_fixture('b')])
632+
def c(request):
633+
return "c" + request.param
634+
635+
@pytest.fixture
636+
def d(c):
637+
return "d" + c
638+
639+
def test_one(d):
640+
assert d in ("dca", "dcb")
641+
""")
642+
reprec = testdir.inline_run('-s', '-v')
643+
reprec.assertoutcome(passed=2)
644+
645+
646+
@pytest.mark.parametrize('autouse', [False, True])
647+
def test_issues23(testdir, autouse):
648+
testdir.makepyfile("""
649+
import pytest
650+
651+
@pytest.fixture(params=[0, 1], autouse={})
652+
def zero(request):
653+
return request.param
654+
655+
@pytest.fixture(params=[1])
656+
def one(request, zero):
657+
return zero * request.param
658+
659+
@pytest.fixture(params=[
660+
pytest.lazy_fixture('one'),
661+
])
662+
def some(request):
663+
return request.param
664+
665+
def test_func(some):
666+
assert some in [0, 1]
667+
668+
""".format(autouse))
669+
reprec = testdir.inline_run('-s', '-v')
670+
reprec.assertoutcome(passed=2)

0 commit comments

Comments
 (0)