Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CarstenGrohmann opened this issue Mar 7, 2023 · 0 comments

Comments

@CarstenGrohmann
Copy link
Contributor

CarstenGrohmann commented Mar 7, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant