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

parametrize implementation doesn't support infinite generators #148

Closed
plammens opened this issue Dec 1, 2020 · 4 comments
Closed

parametrize implementation doesn't support infinite generators #148

plammens opened this issue Dec 1, 2020 · 4 comments

Comments

@plammens
Copy link
Contributor

plammens commented Dec 1, 2020

Per the pytest documentation, the ids parameter of pytest.mark.parametrize also accepts a (possibly infinite) generator of ids, e.g. (f"foo{i}" for i in itertools.count()). (This has the advantage of not having to care about keeping the lenght of argvalues and ids in sync.) However, pytest_cases's custom managing of ids tries to consume the iterator all at once, hence causing the program to hang indefinitely at the collection stage:

p_ids = list(global_ids)

Reproducible example:

import itertools as itt

import pytest
import pytest_cases


@pytest_cases.fixture()
@pytest.mark.parametrize("x", [1, 2, 3], ids=(f"x{i}" for i in itt.count()))
def my_fixture(x):
    return x

def test_foo(my_fixture):
    pass

This happens even if we replace pytest.mark.parametrize with pytest_cases.parametrize.

@smarie
Copy link
Owner

smarie commented Dec 1, 2020

Thanks @plammens ! Indeed, good catch. I'll fix this now

@smarie
Copy link
Owner

smarie commented Dec 1, 2020

Actually could you please provide a reproducible example that enters into this particular case ? Indeed it does not seem to happen
with a basic test:

import itertools
from pytest_cases import parametrize

@parametrize("foo", [1, 2], ids=("foo{%s}" % i for i in itertools.count()))
def test_dummy(foo):
    pass

I guess that it happens with some custom pytest.param or other kind of customization ?

@plammens
Copy link
Contributor Author

plammens commented Dec 1, 2020

Ah! Should have mentioned that this happened only when parametrizing a fixture (i.e. pytest_cases.fixture on top of pytest.mark.parametrize decorators). I've edited the issue to add a reproducible example.

@smarie
Copy link
Owner

smarie commented Dec 2, 2020

Thanks @plammens for your reactivity. Fixing this now

@smarie smarie closed this as completed in b996c20 Dec 2, 2020
smarie pushed a commit that referenced this issue Dec 2, 2020
… also support infinite generators. Improved fix for #148
smarie pushed a commit that referenced this issue Dec 2, 2020
…r]`, it encompasses all cases we dupport for `ids`
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