Skip to content

Lazy fixtures not working at all #33

@brian-barba-hernandez

Description

@brian-barba-hernandez

I had a few lazy fixtures loaded in some of my tests like this:

@pytest.mark.parametrize('user_group', [
        pytest.lazy_fixture('user_group_national_manager'),
        pytest.lazy_fixture('user_group_regional_manager'),	
        pytest.lazy_fixture('user_group_lwi_staff')	
    ])

Now, when the tests are being loaded it fails collecting them with:

/usr/local/lib/python3.6/dist-packages/pluggy/hooks.py:258: in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
/usr/local/lib/python3.6/dist-packages/pluggy/manager.py:67: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
/usr/local/lib/python3.6/dist-packages/pluggy/manager.py:61: in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
/usr/local/lib/python3.6/dist-packages/_pytest/python.py:242: in pytest_pycollect_makeitem
    res = list(collector._genfunctions(name, obj))
/usr/local/lib/python3.6/dist-packages/_pytest/python.py:432: in _genfunctions
    self.ihook.pytest_generate_tests(metafunc=metafunc)
/usr/local/lib/python3.6/dist-packages/pluggy/hooks.py:258: in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
/usr/local/lib/python3.6/dist-packages/pluggy/manager.py:67: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
/usr/local/lib/python3.6/dist-packages/pluggy/manager.py:61: in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
/usr/local/lib/python3.6/dist-packages/pytest_lazyfixture.py:70: in pytest_generate_tests
    normalize_metafunc_calls(metafunc, 'funcargs')
/usr/local/lib/python3.6/dist-packages/pytest_lazyfixture.py:77: in normalize_metafunc_calls
    calls = normalize_call(callspec, metafunc, valtype, used_keys)
/usr/local/lib/python3.6/dist-packages/pytest_lazyfixture.py:101: in normalize_call
    _, fixturenames_closure, arg2fixturedefs = fm.getfixtureclosure([val.name], metafunc.definition.parent)
E   ValueError: not enough values to unpack (expected 3, got 2)

If I changed the code to use tuples or arrays, the tests run but the lazy fixture is not loaded making the tests fail:

@pytest.mark.parametrize('user_group', [
        (pytest.lazy_fixture('user_group_national_manager'),),
        (pytest.lazy_fixture('user_group_regional_manager'),),
        (pytest.lazy_fixture('user_group_lwi_staff'),)
    ])
    assert response.status_code == 200
E   assert 403 == 200
E    +  where 403 = <HttpResponseForbidden status_code=403, "text/html">.status_code

This was working properly before the upgrade to 0.5.0

I tried to use the format specified in the README with no luck. I had to remove the lazy fixture and use a different approach in the meantime.

Any idea of what's broken?

FYI, each fixture just creates a Group and adds the user to the created group. I assert the groups the user belongs to and it belongs to none so the fixture is not loaded when the test runs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions