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

Make LazyFixture iterable #6

Closed
michael-k opened this issue Nov 21, 2016 · 3 comments
Closed

Make LazyFixture iterable #6

michael-k opened this issue Nov 21, 2016 · 3 comments

Comments

@michael-k
Copy link

This does work now:

@pytest.mark.parametrize('arg1', [
   pytest.lazy_fixture('needs_db')
])
@pytest.mark.django_db
def test_some(arg1):
    assert ...

But it's not quite what I need. The fixture needs_db returns a list and I'd like to parametrize test_some with that list:

@pytest.mark.parametrize('arg1', pytest.lazy_fixture('needs_db'))
@pytest.mark.django_db
def test_some(arg1):
    assert ...

This fails: TypeError: 'LazyFixture' object is not iterable

Is it possible to support this use case? I'm not familiar with pytest's internals. :/

@TvoroG
Copy link
Owner

TvoroG commented Nov 21, 2016

@michael-k thanks again for reporting a bug :) I'll take a look

@TvoroG
Copy link
Owner

TvoroG commented Nov 21, 2016

Well, I think I've just now realized what your use case :) Do you want to parametrize test with some data from db? If so, it's not quite possible. When pytest.mark.parametrize wants to iterate through your data (argument values), pytest_django autouse fixtures are not yet executed, so there is no even test db.

@michael-k
Copy link
Author

That's what I feared. :/

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

2 participants