Skip to content

cannot use a lazy fixture if it directly returns a list #25

Open

Description

@drake-mer
# -*- 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

Activity

  1. tnixon commented on Jul 2, 2019

    @tnixon

    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)

  2. davidstrouk commented on May 20, 2021

    @davidstrouk

    Any news regarding this? I know this thread is old, but I have the exact same issue.

  3. Ben621 commented on Dec 13, 2021

    @Ben621

    Hey i have the same problem
    Someone find a workaround @davidstrouk @tnixon ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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