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

Nested fixtures are not seen by pytest_lazyfixture unless autouse=True #23

Open
wikiped opened this issue Feb 5, 2018 · 0 comments
Open

Comments

@wikiped
Copy link

wikiped commented Feb 5, 2018

Using modified example from the official Usage instructions:

@fixture(params=[0, 1], autouse=True)
def zero_one(request):
    return request.param

@fixture(params=[1])
def one(request, zero_one):
    return zero_one * request.param

@fixture(params=[0, 1], autouse=False)
def zero_two(request):
    return request.param

@fixture
def two(request, zero_two):
    return zero_two * request.param

@fixture(params=[
    lazy_fixture('one'),
])
def some_auto(request):
    return request.param

@fixture(params=[
    lazy_fixture('two')
])
def some(request):
    return request.param

def test_pytest_can_see_all_fixtures(zero_one, zero_two, one, two):
    for f in (zero_one, zero_two, one, two):
        assert isinstance(f, int)

def test_func_autouse(some_auto):
    assert some_auto in [0, 1]

def test_func_no_autouse(some):
    assert some in [0, 1]

The last test will fail unexpectedly with error:

C:\Anaconda\lib\site-packages\_pytest\python.py:680: ValueError

During handling of the above exception, another exception occurred:

request = <FixtureRequest for <Function 'test_func_no_autouse[0-some0]'>>

    def fill(request):
        item = request._pyfuncitem
        fixturenames = item.fixturenames
        argnames = item._fixtureinfo.argnames
    
        for fname in fixturenames:
            if fname not in item.funcargs and fname not in argnames:
                item.funcargs[fname] = request.getfixturevalue(fname)
    
        if hasattr(item, 'callspec'):
            for param, val in sorted_by_dependency(item.callspec.params, fixturenames):
                if is_lazy_fixture(val):
>                   item.callspec.params[param] = request.getfixturevalue(val.name)
E                   Failed: The requested fixture has no parameter defined for the current test.
E                   
E                   Requested fixture 'zero_two' defined in:
E                   some_package\tests\test_example.py:47
E                   
E                   Requested here:
E                   C:\Anaconda\lib\site-packages\_pytest\fixtures.py:523

C:\Anaconda\lib\site-packages\pytest_lazyfixture.py:40: Failed

For some reason pytest_lazyfixture doesn't see fixtures that depend on other fixtures that pytest can see unless autouse=True in the lowest level fixture.

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