Use your fixtures in @pytest.mark.parametrize.
pip install pytest-lazy-fixture
pytest-lazy-fixture lets you use a fixture as one of the values passed
in @pytest.mark.parametrize:
import pytest from pytest_lazyfixture import lazy_fixture @pytest.fixture def one(): return 1 @pytest.mark.parametrize('arg1,arg2', [ ('val1', lazy_fixture('one')), ]) def test_func(arg1, arg2): assert arg2 == 1
This can be even more useful when the fixture is itself parametrized:
import pytest from pytest_lazyfixture import lazy_fixture @pytest.fixture(params=[1, 2]) def one(request): return request.param @pytest.mark.parametrize('arg1,arg2', [ ('val1', lazy_fixture('one')), ]) def test_func(arg1, arg2): assert arg2 in [1, 2]
Also you can use it as a parameter in @pytest.fixture:
import pytest from pytest_lazyfixture import lazy_fixture @pytest.fixture(params=[ lazy_fixture('one'), lazy_fixture('two') ]) def some(request): return request.param @pytest.fixture def one(): return 1 @pytest.fixture def two(): return 2 def test_func(some): assert some in [1, 2]
Please see tests for more examples.
Contributions are very welcome. Tests can be run with tox.
Distributed under the terms of the MIT license,
pytest-lazy-fixture is free and open source software
If you encounter any problems, please file an issue along with a
detailed description.