pytest-testinfra
pytest-testinfra copied to clipboard
Exclude or Include hosts per test function
Workaround http://pastebin.com/TqGfqVZ3
Well, I wanted to be able to skip a test based on a remote command. Here the command was 'hostname -s', but it could have been anything else. Is there a way to do that?
Doesn't @pytest.mark.testinfra_hosts
already do something like that? See https://github.com/philpep/testinfra/blob/master/testinfra/test/test_backends.py
@pytest.mark.testinfra_hosts does not work with Salt, we had to use the suggested workaround.
My team would be happy to extend @pytest.mark.testinfra_hosts
to support Salt.
Could you point us in the right direction? Thanks a lot.
Do you have an idea @philpep? :)
FWIW, a (more ansible specific) workaround. My use case is ansible group intersection. I'm pretty new to python and to pytest, but this seems to be elegant. The approach is to define a conftest.py with a fixture:
@pytest.fixture(scope='class')
def groups(host):
return host.ansible.get_variables()['group_names']
Then add groups
to the test function parameters, and add a line like
if 'GROUP_NAME' in groups:
This avoids pytest.skip()
which, for my usage is a plus.