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

Cannot stack @parametrize_with_cases() if cases use fixtures and have the same suffix name #117

Closed
jcwilson opened this issue Jul 28, 2020 · 4 comments

Comments

@jcwilson
Copy link

Running this code:

from pytest_cases import parametrize_with_cases

def a_case(monkeypatch):
    return True

def b_case(freezer):
    return True

@parametrize_with_cases("a", cases=".", prefix="a_")
@parametrize_with_cases("b", cases=".", prefix="b_")
def test_something(a, b):
    pass

results in this error:

Test session starts (platform: linux, Python 3.8.4, pytest 5.4.3, pytest-sugar 0.9.4)
rootdir: /code/components/echo, inifile: pytest.ini
plugins: mock-3.2.0, cases-2.0.4, sugar-0.9.4, freezegun-0.4.1, cov-2.10.0
collecting ...
―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ERROR collecting tests/test_authentication_middleware.py ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――tests/test_authentication_middleware.py:14: in <module>
    def test_something(a, b):
/home/aladdin-user/.local/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:99: in _apply_parametrization
    argvalues = get_parametrize_args(cases_funs)
/home/aladdin-user/.local/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:238: in get_parametrize_args
    return [c for _f in cases_funs for c in case_to_argvalues(_f)]
/home/aladdin-user/.local/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:238: in <listcomp>
    return [c for _f in cases_funs for c in case_to_argvalues(_f)]
/home/aladdin-user/.local/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:291: in case_to_argvalues
    raise NotImplementedError("We should check if this is the same or another and generate a new name in that "
E   NotImplementedError: We should check if this is the same or another and generate a new name in that case

However, if I remove monkeypatch or freezer from one of the cases, or if I change the name of one of the cases, it runs the test.

@smarie
Copy link
Owner

smarie commented Jul 28, 2020

Thanks for reporting ! I'll have a look

@smarie
Copy link
Owner

smarie commented Jul 29, 2020

Sorry I finally take the time to look now actually - I had to close a series of other things.
I was able to reproduce the issue (note for future readers: no need to use the freezer plugin, using request fixture instead of freezer also produces the same bug)

When pytest cases collects some cases that require a fixture, it creates a fixture for that case. This fixture is registered locally in the current module. But of course local fixtures need to have unique names. In your example the name (that I derive from the case id) is case in both situations. I therefore changed a bit the logic in order to guarantee uniqueness. I should release the fix soon.

@smarie smarie closed this as completed in 6bee356 Jul 29, 2020
@jcwilson
Copy link
Author

Thanks for the quick response!

And yeah, there's nothing special about the fixture names in my example. Just had them handy. Sorry if that added some confusion.

@smarie
Copy link
Owner

smarie commented Jul 30, 2020

2.1.0 was released, please feel free to reopen if it does not fix the issue for you ! Thanks a lot for contributing

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