{"id":2234,"library":"pytest-lazy-fixtures","title":"pytest-lazy-fixtures","description":"pytest-lazy-fixtures is a pytest plugin that allows the use of fixtures directly within `pytest.mark.parametrize` arguments. It supports injecting fixtures into various data structures and accessing fixture attributes. The library is actively maintained with regular releases and bug fixes, currently at version 1.4.0.","status":"active","version":"1.4.0","language":"en","source_language":"en","source_url":"https://github.com/dev-petrov/pytest-lazy-fixtures","tags":["pytest","testing","fixtures","parametrization"],"install":[{"cmd":"pip install pytest-lazy-fixtures","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core testing framework integration, as it's a plugin for pytest.","package":"pytest","optional":false},{"reason":"Requires Python 3.8 or newer.","package":"python","optional":false}],"imports":[{"note":"The original 'pytest-lazy-fixture' (singular) package is a different, older project and often incompatible with newer pytest versions. Ensure you import from 'pytest_lazyfixtures' (plural).","wrong":"from pytest_lazyfixture import lazy_fixture","symbol":"lf","correct":"from pytest_lazyfixtures import lf"},{"note":"Similar to 'lf', ensure 'lfc' is imported from the correct 'pytest_lazyfixtures' (plural) package.","wrong":"from pytest_lazyfixture import lazy_fixture_callable","symbol":"lfc","correct":"from pytest_lazyfixtures import lfc"}],"quickstart":{"code":"import pytest\nfrom pytest_lazyfixtures import lf\n\n@pytest.fixture()\ndef my_fixture_value():\n    return 'Hello from fixture!'\n\n@pytest.mark.parametrize('param_name', [lf('my_fixture_value')])\ndef test_example(param_name):\n    assert param_name == 'Hello from fixture!'\n\n# Example with a dictionary and attribute access\nclass MyObject:\n    def __init__(self, value):\n        self.value = value\n\n@pytest.fixture()\ndef an_object():\n    return MyObject(42)\n\n@pytest.mark.parametrize('data', [\n    {'key': lf('my_fixture_value')},\n    {'number': lf('an_object.value')}\n])\ndef test_complex_data(data):\n    if 'key' in data:\n        assert data['key'] == 'Hello from fixture!'\n    if 'number' in data:\n        assert data['number'] == 42\n","lang":"python","description":"This quickstart demonstrates the basic usage of `lf` (lazy_fixture) to inject a fixture's return value directly into `pytest.mark.parametrize`. It also shows how to use `lf` with complex data structures like dictionaries and how to access attributes of a fixture's return value using dot notation."},"warnings":[{"fix":"Use `pip install pytest-lazy-fixtures` and `from pytest_lazyfixtures import lf`.","message":"Be aware of two similarly named packages: `pytest-lazy-fixture` (singular) and `pytest-lazy-fixtures` (plural). The singular version is older and often incompatible with `pytest` versions 8.0.0 and newer. Ensure you are installing and importing from `pytest-lazy-fixtures` to avoid compatibility issues and to use the actively maintained library.","severity":"breaking","affected_versions":"pytest-lazy-fixture (singular) with pytest >= 8.0.0. pytest-lazy-fixtures (plural) is unaffected by this specific incompatibility."},{"fix":"Explicitly use `lf()` for parameters where implicit injection is not desired, or ensure parameter names do not clash with fixture names if implicit injection is to be avoided. The documentation recommends implicit injection as the standard behavior for `lfc`.","message":"Starting with version 1.4.0, `lfc` (lazy_fixture_callable) supports implicit fixture injection. If a callable's parameter name matches a fixture name, the fixture will be resolved and passed automatically, provided no explicit value or default is present for that parameter. This might lead to unexpected fixture resolution if not fully understood.","severity":"gotcha","affected_versions":">=1.4.0"},{"fix":"Use `lf('my_fixture')` instead of `'my_fixture'` when embedding fixtures in parameterized data or when a nested fixture needs to be resolved.","message":"When using fixtures within complex data structures (e.g., dictionaries, lists) passed to `@pytest.mark.parametrize`, or when a fixture itself depends on another fixture that needs to be resolved, always wrap the fixture name with `lf()` to ensure proper resolution. Directly passing string names will not work and the fixture will not be evaluated.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use `from pytest_lazyfixtures import lf` in `conftest.py` and other test files where `lf` is needed.","message":"Avoid relying on `pytest.lazy_fixture` if placed directly in `conftest.py` or at the top level of a test file, as pytest's plugin loading order might cause `pytest.lazy_fixture` (a global attribute added by the plugin) to not exist during early fixture registration. Always import `lf` (or `lazy_fixture` for explicit aliasing) directly from `pytest_lazyfixtures` in all files where it's used.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}