Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load lazy fixtures for dict keys #23

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"}
Loading