Pytest Lazy Fixture
pytest-lazy-fixture is a plugin for the pytest testing framework that allows users to pass fixtures as values directly within `pytest.mark.parametrize` decorators. This simplifies test parameterization by enabling the reuse of fixtures where direct fixture injection is not typically supported. The current version is 0.6.3, but the library is no longer actively maintained and has known compatibility issues with newer pytest versions.
Warnings
- breaking pytest-lazy-fixture is incompatible with pytest versions 8.0.0 and newer. Attempting to use it with these versions will lead to test failures.
- deprecated The `pytest-lazy-fixture` library is no longer actively maintained. This means new features, bug fixes, or compatibility updates for newer pytest versions are unlikely.
- gotcha Fixtures used with `lazy_fixture` are resolved during test execution, not at collection time. This means you cannot use `lazy_fixture` to define parameters that are evaluated during the pytest collection phase for certain advanced scenarios.
- breaking Version 0.4.0 introduced a requirement for `pytest >= 3.3.0`. Older pytest versions will not be compatible with `pytest-lazy-fixture` versions 0.4.0 and above.
Install
-
pip install pytest-lazy-fixture
Imports
- lazy_fixture
from pytest_lazyfixture import lazy_fixture
Quickstart
import pytest
from pytest_lazyfixture import lazy_fixture
@pytest.fixture
def my_fixture():
return 'Hello from fixture!'
@pytest.mark.parametrize('param_arg', [lazy_fixture('my_fixture')])
def test_example(param_arg):
assert param_arg == 'Hello from fixture!'
# To run this, save as a .py file (e.g., test_lazy.py) and run 'pytest'