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 #20

Closed
gordiig opened this issue Jul 15, 2024 · 0 comments · Fixed by #23
Closed

Load lazy fixtures for dict keys #20

gordiig opened this issue Jul 15, 2024 · 0 comments · Fixed by #23
Assignees

Comments

@gordiig
Copy link

gordiig commented Jul 15, 2024

Right now, if I am creating a dict in parametrize with a lf (of lfc) key, this key is not lazy loaded, but stays as is. All because of the code from the lib in loader.py:

def load_lazy_fixtures(value, request: pytest.FixtureRequest):
    # ...
    if type(value) is dict:  # noqa: E721
        return {key: load_lazy_fixtures(value, request) for key, value in value.items()}
   # ...

Why not making keys to be lazy loadable too?

Test example:

@pytest.fixture
def fixture_a_() -> str:
    return 'a'


@pytest.fixture
def fixture_b_() -> str:
    return 'b'


@pytest.mark.parametrize(
    'test_dict, expected',
    [
        [{'a': 'b'}, True],
        [{'b': 'a'}, False],
        [{lf('fixture_a_'): lf('fixture_b_')}, True],
    ]
)
def test_dict_a_b(test_dict: str, expected: bool):
    assert (test_dict == {'a': 'b'}) == expected

Expected behavior

All tests passed

Actual behavior

>       assert (test_dict == {'a': 'b'}) == expected
E       AssertionError: assert ({fixture_a_: 'b'} == {'a': 'b'}
E         
E         Left contains 1 more item:
E         {fixture_a_: 'b'}
E         Right contains 1 more item:
E         {'a': 'b'}
E         Use -v to get more diff) == True
@dev-petrov dev-petrov self-assigned this Jul 17, 2024
@dev-petrov dev-petrov linked a pull request Jul 17, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants