pytest-lazy-fixture
pytest-lazy-fixture copied to clipboard
cannot use a lazy fixture if it directly returns a list
# -*- coding: utf-8 -*-
import string
import pytest
@pytest.fixture
def list_of_tuple_for_testing():
yield [(ord(x), x) for x in string.ascii_uppercase]
@pytest.mark.parametrize(
'chr_code, chr_object',
pytest.lazy_fixture('list_of_tuple_for_testing')
)
def test_all_files(chr_code, chr_object):
assert chr(chr_code) == chr_object
================================================================================ ERRORS ================================================================================
________________________________________________________________ ERROR collecting test_lazy_fixture.py _________________________________________________________________
/usr/lib/python3.6/site-packages/pluggy/__init__.py:617: in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
/usr/lib/python3.6/site-packages/pluggy/__init__.py:222: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
/usr/lib/python3.6/site-packages/pluggy/__init__.py:216: in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
/usr/lib/python3.6/site-packages/_pytest/python.py:240: in pytest_pycollect_makeitem
res = list(collector._genfunctions(name, obj))
/usr/lib/python3.6/site-packages/_pytest/python.py:432: in _genfunctions
self.ihook.pytest_generate_tests(metafunc=metafunc)
/usr/lib/python3.6/site-packages/pluggy/__init__.py:617: in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
/usr/lib/python3.6/site-packages/pluggy/__init__.py:222: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
/usr/lib/python3.6/site-packages/pluggy/__init__.py:216: in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
/usr/lib/python3.6/site-packages/_pytest/python.py:161: in pytest_generate_tests
metafunc.parametrize(*marker.args, **marker.kwargs)
/usr/lib/python3.6/site-packages/_pytest/python.py:872: in parametrize
argnames, argvalues, self.function, self.config
/usr/lib/python3.6/site-packages/_pytest/mark/structures.py:106: in _for_parametrize
for x in argvalues
E TypeError: 'LazyFixture' object is not iterable
I've just run into a situation where this would be very useful to have! (Code generates list of objects, I'd like to run a battery of tests on each - by passing the list to a parameterization)
Any news regarding this? I know this thread is old, but I have the exact same issue.
Hey i have the same problem Someone find a workaround @davidstrouk @tnixon ?