diff --git a/doc/source/invocation.rst b/doc/source/invocation.rst index 1d744e54..bee788a3 100644 --- a/doc/source/invocation.rst +++ b/doc/source/invocation.rst @@ -35,6 +35,12 @@ You can also set hosts per test module:: [....] +If you need to filter or update generated host list (f.e. after ["ansible://somegroup"]), +you can use testinfra_hosts_update function: + + def testinfra_hosts_update(host_list): + return [host_list[0]] + Parallel execution ~~~~~~~~~~~~~~~~~~ diff --git a/testinfra/plugin.py b/testinfra/plugin.py index bbad24a1..170b26ee 100644 --- a/testinfra/plugin.py +++ b/testinfra/plugin.py @@ -117,6 +117,10 @@ def pytest_generate_tests(metafunc): ansible_inventory=metafunc.config.option.ansible_inventory, force_ansible=metafunc.config.option.force_ansible, ) + if hasattr(metafunc.module, "testinfra_hosts_update"): + if not callable(metafunc.module.testinfra_update.callable): + pytest.fail("testinfra_hosts_update must be a function") + params = metafunc.module.testinfra_hosts_update(params) params = sorted(params, key=lambda x: x.backend.get_pytest_id()) ids = [e.backend.get_pytest_id() for e in params] metafunc.parametrize(