pytest-testinfra icon indicating copy to clipboard operation
pytest-testinfra copied to clipboard

run 2 backend in same file

Open spham opened this issue 3 years ago • 0 comments

Hi I wish to play 2 backend in same test.py file

because i need to run ansible backend for some scripts and paramiko for other

# for paramiko
def test_100_service_rabbitmq_server_is_running(host):
    assert host.service("rabbitmq-server").is_running
    assert host.service("rabbitmq-server").is_enabled

# for ansible
def test_ansible(host):
    host.ansible(
        'template', 'src="templates/rabbitmq.conf.j2" dest="/etc/rabbitmq/rabbitmq.conf"', check=False)

it work when i passed params with command:

py.test --connection=ansible --ansible-inventory=".vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory" --ssh-config=.vagrant/ssh-config tests.py

or

py.test --hosts=default --ssh-config=.vagrant/ssh-config tests.py -v

but it's not work with both in same time.

error is

    @functools.wraps(func)
    def wrapper(self, *args, **kwargs):
        if not self._host.backend.HAS_RUN_ANSIBLE:
>           raise RuntimeError(
                ("Ansible module is only available with ansible " "connection backend")
            )
E           RuntimeError: Ansible module is only available with ansible connection backend

is it possible to embbed params in file and switch host when needed ?

thanks for help or idea regards

spham avatar Feb 02 '22 11:02 spham