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

Parametrized lazy fixture - incompatibility with pytest-lazy-fixture #16

Closed
mikicz opened this issue Apr 9, 2024 · 4 comments · Fixed by #25
Closed

Parametrized lazy fixture - incompatibility with pytest-lazy-fixture #16

mikicz opened this issue Apr 9, 2024 · 4 comments · Fixed by #25
Assignees

Comments

@mikicz
Copy link

mikicz commented Apr 9, 2024

Hello, I came across a incompatibility with pytest-lazy-fixture when using lazy fixtures with parametrized fixtures.

If you take this example with pytest-lazy-fixture:

import pytest

@pytest.fixture(params=["a", "b"])
def some_fixture_a(request):
    return request.param

@pytest.fixture(params=["c", "d"])
def some_fixture_b(request):
    return request.param

@pytest.mark.parametrize(
    "some_fixture", [pytest.lazy_fixture("some_fixture_a"), pytest.lazy_fixture("some_fixture_b")]
)
def test_with_multiple_fixtures(some_fixture):
    pass

It behaves as I would expect, runs the test 4 times:

test_pytest_lazy_fixture.py::test_with_multiple_fixtures[some_fixture_a-a] PASSED           [ 25%]
test_pytest_lazy_fixture.py::test_with_multiple_fixtures[some_fixture_a-b] PASSED           [ 50%]
test_pytest_lazy_fixture.py::test_with_multiple_fixtures[some_fixture_b-c] PASSED           [ 75%]
test_pytest_lazy_fixture.py::test_with_multiple_fixtures[some_fixture_b-d] PASSED          [100%]

However, when you migrate to pytest-lazy-fixtures, this stops working:

import pytest

@pytest.fixture(params=["a", "b"])
def some_fixture_a(request):
    return request.param

@pytest.fixture(params=["c", "d"])
def some_fixture_b(request):
    return request.param

@pytest.mark.parametrize(
    "some_fixture", [pytest.lazy_fixtures("some_fixture_a"), pytest.lazy_fixtures("some_fixture_b")]
)
def test_with_multiple_fixtures(some_fixture):
    pass

The output is:

test_pytest_lazy_fixtures.py::test_with_multiple_fixtures[some_fixture_a] ERROR               [ 50%]
test_pytest_lazy_fixtures.py::test_with_multiple_fixtures[some_fixture_b] ERROR               [100%]

============================================== ERRORS ===============================================
___________________ ERROR at setup of test_with_multiple_fixtures[some_fixture_a] ___________________
The requested fixture has no parameter defined for test:
    test_pytest_lazy_fixtures.py::test_with_multiple_fixtures[some_fixture_a]

Requested fixture 'some_fixture_a' defined in:
test_pytest_lazy_fixtures.py:5

Requested here:
venv/lib64/python3.11/site-packages/pytest_lazy_fixtures/lazy_fixture.py:26
___________________ ERROR at setup of test_with_multiple_fixtures[some_fixture_b] ___________________
The requested fixture has no parameter defined for test:
    test_pytest_lazy_fixtures.py::test_with_multiple_fixtures[some_fixture_b]

Requested fixture 'some_fixture_b' defined in:
test_pytest_lazy_fixtures.py:10

Requested here:
venv/lib64/python3.11/site-packages/pytest_lazy_fixtures/lazy_fixture.py:26
====================================== short test summary info ======================================
ERROR test_pytest_lazy_fixtures.py::test_with_multiple_fixtures[some_fixture_a] - Failed: The requested fixture has no parameter defined for test:
ERROR test_pytest_lazy_fixtures.py::test_with_multiple_fixtures[some_fixture_b] - Failed: The requested fixture has no parameter defined for test:
@dev-petrov
Copy link
Owner

Hello! What version are you using? I've tried 1.1.0 and your test has successfully passed

@mikicz
Copy link
Author

mikicz commented Jul 18, 2024

Huh! I can't replicate anymore, so closing.

@mikicz mikicz closed this as completed Jul 18, 2024
@yugokato
Copy link

yugokato commented Jul 22, 2024

@dev-petrov I can still reproduce the issue in v1.1.0. The only change I made in the above example code is to use lf from pytest_lazy_fixtures instead of pytest.lazy_fixtures due to #21

pytest==7.4.4
pytest-lazy-fixtures==1.1.0

UPDATE: Looks like the issue happens with the pytest version I'm using. Just tried the same code with pytest 8.3.1 and it worked fine.
Would you take a look?

@dev-petrov dev-petrov reopened this Jul 22, 2024
@dev-petrov dev-petrov self-assigned this Jul 22, 2024
@dev-petrov dev-petrov linked a pull request Jul 22, 2024 that will close this issue
@dev-petrov
Copy link
Owner

Try v1.1.1

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.

3 participants