Skip to content

Commit

Permalink
Workaround for pytest issue #3542 (#346)
Browse files Browse the repository at this point in the history
Implement workaround for pytest issue [#3542](pytest-dev/pytest#3542)

There seems to be a bug in pytest where metafunc.parametrize breaks
fixture scope. By creating a fixture and parameterizing it indirectly
scope can be maintained
  • Loading branch information
barnabasJ authored and philpep committed Sep 12, 2018
1 parent 074e809 commit 4de836e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion testinfra/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def TestinfraBackend(host):
return host.backend


@pytest.fixture(scope="module")
def _testinfra_host(request):
return request.param


@pytest.fixture(scope="module")
def host(_testinfra_host):
return _testinfra_host
Expand Down Expand Up @@ -149,7 +154,7 @@ def pytest_generate_tests(metafunc):
params = sorted(params, key=lambda x: x.backend.get_pytest_id())
ids = [e.backend.get_pytest_id() for e in params]
metafunc.parametrize(
"_testinfra_host", params, ids=ids, scope="module")
"_testinfra_host", params, ids=ids, scope="module", indirect=True)


def pytest_collection_finish(session):
Expand Down

0 comments on commit 4de836e

Please sign in to comment.