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

TypeError: 'LazyFixture' object is not iterable #56

Open
ChristianF88 opened this issue Feb 25, 2022 · 3 comments
Open

TypeError: 'LazyFixture' object is not iterable #56

ChristianF88 opened this issue Feb 25, 2022 · 3 comments

Comments

@ChristianF88
Copy link

Hi there,

I am running into issues with using a fixture, that loads a list of parameters that I want to use to parametrize tests. I am not sure, whether that is something, that can be done with your package and I just can't figure it out, or whether that would be a new feature.

Here is a example on what I want to achieve:

import pytest

@pytest.fixture()
def one(tmp_path):
    return list(str(tmp_path))

@pytest.mark.parametrize("char", pytest.lazy_fixture('one'))
def test_func(char):
    assert char.isascii()

Do you have an idea on how to get my code running?

Thanks a lot!

@ChristianF88
Copy link
Author

So it seems like I am not the only one in demand of this feature. Any plans on whether that could be implemented at some point?

@notamonad
Copy link

+1 for this feature request

@djhoese
Copy link

djhoese commented Sep 1, 2022

I found this issue while looking for something else. It isn't what I'm looking for, but now I'm curious by your problem. You want the fixture to be the list of parameters? I think normally you would do the parametrization on the fixture itself and then use that fixture in the test function. This is kind of shown in the README of this project:

import pytest
from pytest_lazyfixture import lazy_fixture

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

@pytest.mark.parametrize('arg1,arg2', [
    ('val1', lazy_fixture('one')),
])
def test_func(arg1, arg2):
    assert arg2 in [1, 2]

But also talked about in the pytest docs here:

https://docs.pytest.org/en/6.2.x/fixture.html#parametrizing-fixtures

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

3 participants