Skip to content

Commit

Permalink
Load lazy fixtures for dict keys (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-petrov authored Jul 17, 2024
1 parent 0123c94 commit 64f6877
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pytest_lazy_fixtures/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def load_lazy_fixtures(value, request: pytest.FixtureRequest):
return value.load_fixture(request)
# we need to check exact type
if type(value) is dict: # noqa: E721
return {key: load_lazy_fixtures(value, request) for key, value in value.items()}
return {load_lazy_fixtures(key, request): load_lazy_fixtures(value, request) for key, value in value.items()}
# we need to check exact type
elif type(value) in {list, tuple, set}:
return type(value)([load_lazy_fixtures(value, request) for value in value])
Expand Down
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,13 @@ def service5(fixture1):
)
def fixture2(request):
return None


@pytest.fixture
def fixture_a() -> str:
return "a"


@pytest.fixture
def fixture_b() -> str:
return "b"
10 changes: 10 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,13 @@ def fixture1(request):

def test_foo(fixture2):
pass


@pytest.mark.parametrize(
"test_dict",
[
{lf("fixture_a"): lf("fixture_b")},
],
)
def test_dict_a_b(test_dict):
assert test_dict == {"a": "b"}

0 comments on commit 64f6877

Please sign in to comment.