Skip to content

Overriding host fixture causes an AttributeError: 'SubRequest' object has no attribute 'param' #687

Open
@CarstenGrohmann

Description

@CarstenGrohmann

Hi,

I tried to replace the host fixture with an own implementation to skip test modules based on Ansible groups. I simply created a new host fixture in tests/conftest.py.

$  cat hosts
[local]
localhost

[skip_test_mytest_file]
mytesttarget

$ cat tests/conftest.py
import pytest

@pytest.fixture(scope='module')
def host(host, request):
    for groupname in host.ansible.get_variables()["group_names"]:
        if groupname.startswith("skip_%s" % request.module.__name__):
            pytest.skip()
    return host

But unfortunately the code fails with:

request = <SubRequest '_testinfra_host' for <Function test_mytest>>

    @pytest.fixture(scope="module")
    def _testinfra_host(request):
>       return request.param
E       AttributeError: 'SubRequest' object has no attribute 'param'

../../virtualenv/lib64/python3.10/site-packages/testinfra/plugin.py:28: AttributeError

It looks like the optional param attribute is missing and this triggers the issue.

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

The current workaround is to name the new fixture ansiblehost and use it in my code. However, this leads to a lot of code changes.

Please provide a possibility to replace the host fixture with an own implementation.

Thank you,
Carsten

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions