aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/plugin.py
blob: de7d75a4f79b00df5e97325d248cd937b5e01fbb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pytest

from .lazy_fixture import LazyFixtureWrapper, lf
from .lazy_fixture_callable import lfc
from .loader import load_lazy_fixtures
from .normalizer import normalize_metafunc_calls


def pytest_configure():
    pytest.lazy_fixtures = lf
    pytest.lazy_fixtures_callable = lfc


@pytest.hookimpl(tryfirst=True)
def pytest_fixture_setup(fixturedef, request):
    val = getattr(request, "param", None)
    if val is not None:
        request.param = load_lazy_fixtures(val, request)


def pytest_make_parametrize_id(config, val, argname):
    if isinstance(val, LazyFixtureWrapper):
        return val.name


@pytest.hookimpl(hookwrapper=True)
def pytest_generate_tests(metafunc):
    yield

    normalize_metafunc_calls(metafunc)