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

Possible to expand the fixture return value in parametrize? #9

Closed
schtibe opened this issue Dec 13, 2016 · 7 comments
Closed

Possible to expand the fixture return value in parametrize? #9

schtibe opened this issue Dec 13, 2016 · 7 comments

Comments

@schtibe
Copy link

schtibe commented Dec 13, 2016

I would like to parametrize a test with the return value of a fixture.

Example:

@pytest.fixture
def links(browser): // assume broser was a fixture
    return browser.find_by_tag('a')

@pytest.mark.parametrize("link", links) // here expand the links fixture return value
def test_func(link):
     // test that link here

Is this possible with pytest-lazy-fixture? (or maybe even pytest itself?) Or might it be a nice feature?

@TvoroG
Copy link
Owner

TvoroG commented Dec 13, 2016

Hi! Yes, you can do it with pytest-lazy-fixture:

@pytest.fixture
def links(browser): # assume browser was a fixture
    return browser.find_by_tag('a')

@pytest.mark.parametrize("link", [
    pytest.lazy_fixture('links')
]) # here expand the links fixture return value
def test_func(link):
     # test that link here

@schtibe
Copy link
Author

schtibe commented Dec 13, 2016

This way i get following error:

   return [LazyFixture(name) for name in names]
E   TypeError: 'function' object is not iterable

@TvoroG
Copy link
Owner

TvoroG commented Dec 13, 2016

There was a similar issue: #6. For now It's not possible to implement this feature.

@TvoroG
Copy link
Owner

TvoroG commented Dec 13, 2016

If you have some other issues or questions feel free to reopen it or create another one

@TvoroG TvoroG closed this as completed Dec 13, 2016
@tovmeod
Copy link

tovmeod commented Feb 5, 2019

I'm interested in something like that. Did the situation change? is it possible to implement this today? if not, why not?

@TvoroG
Copy link
Owner

TvoroG commented Feb 6, 2019

Check out pytest-dev/pytest#4050. I think the main reason here is that you want to generate test cases during runtime, and pytest can do it only during the collection stage. Although I'm not sure.

@jxramos
Copy link

jxramos commented Feb 20, 2019

It is looking like this collection stage constraint is indeed what may be lurking here...

per design all parametization happens at collection time
StackOverflow Answer: pytest test needs parametrization at collection phase and at setup time

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

4 participants