Skip to content
Discussion options

You must be logged in to vote

Hi @jmlemetayer

The reason params=get_devices() is empty is that the fixture decorator is evaluated while the module/plugin is being imported. Your devices are only populated later in pytest_configure.

For parameters derived from pytest configuration, use pytest_generate_tests, which runs during collection and has access to metafunc.config.

For example:

@pytest.fixture(scope="session")
def device(request):
    # Expensive setup can happen here.
    return connect_to_device(request.param)


def pytest_generate_tests(metafunc):
    if "device" in metafunc.fixturenames:
        config_file = metafunc.config.getoption("--config-file")
        devices = load_device_descriptions(config_file)

 …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jmlemetayer
Comment options

Answer selected by jmlemetayer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants