-
Notifications
You must be signed in to change notification settings - Fork 40
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
Using a case function with no suffix leads to an unexpected hypen symbol in the test ids #142
Comments
I've looked into it, and it seems these lines are to blame: python-pytest-cases/pytest_cases/case_parametrizer_new.py Lines 299 to 300 in 1d33f2f
If I change it so the case where there is no return tuple(lazy_value(partial(case_fun, **c.funcargs), id="%s-%s" % (case_id, c.id) if case_id else "%s" % c.id, marks=c.marks)
for c in meta._calls) my problem goes away |
I @romanponomaryov , which version of
Indeed the Could it be that in you actual code, you have a case function named |
Hey @smarie , sorry for misinforming you. @pytest.mark.parametrize('dummy_amount', [1, 0, -1])
def case_amount(dummy_amount):
return dummy_amount
@parametrize_with_cases('dummy_amount', prefix="case_amount", cases=".")
def test_amount(dummy_amount):
<some code here> I am using the latest version of pytest-cases (2.3.0) |
Now I understand and I am able to reproduce it. I fixed it for next version: Thanks a lot for spotting this issue ! |
Hi @smarie , @parametrize('dummy_amount', [0, 3, -4, -1])
def case_list(dummy_amount):
return dummy_amount
remove_redundant_hyphen = lambda **args: "-".join(str(v)[1:] for n, v in args.items())
@parametrize_with_cases('dummy_amount', prefix="case_list", cases='.', idgen=remove_redundant_hyphen)
def test_list(dummy_amount):
assert True This works ok and I get in report:
But this does not work with parametrizing more than one value: @parametrize('dummy_amount, exp_amount', [(0, 3), (-4, -1), (5, 8)])
def case_tuples(dummy_amount, exp_amount):
return dummy_amount, exp_amount
remove_redundant_hyphen = lambda **args: "-".join(str(v)[1:] for n, v in args.items())
@parametrize_with_cases('dummy_amount, exp_amount', prefix="case_tuples", cases='.', idgen=remove_redundant_hyphen2)
def test_tuples(dummy_amount, exp_amount):
assert True and I get in report:
while I'm aiming at getting same result as with
The output in report seems to be not affected at all, no matter how I change the function provided to tuples = [(0, 3), (-4, -1), (5, 8)]
@parametrize_with_cases('dummy_amount, exp_amount', prefix="case_tuples", cases='.', ids=[str(x) for x in tuples]) |
Hi @romanponomaryov , I think that there was some misunderstanding here. The easiest workaround until the new release ships is just to use a non empty case id. So the case function names should have a suffix after the prefix, for example: @parametrize('dummy_amount', [0, 3, -4, -1])
def case_list_a(dummy_amount): # <------------ notice the name here
return dummy_amount
def case_list_b(): # <------------ notice the name here
return 12
@parametrize_with_cases('amount', prefix="case_list_", cases='.')
def test_list(amount):
assert True Yields:
I do not think that there is a need to remove the case function name from the test id in the particular situation where there is a single case function. Do you ? That would require quite cumbersome/specific code for something that does not bring much to the end user in my opinion.. |
Hey @smarie |
Hi @smarie!
I've noticed that if I apply
@parametrize
or@pytest.mark.parametrize
to my cases function like this:then in the test report instead of
I get
Moving case function to another file makes no difference.
Is parametrizing cases even a proper way? I just don't want to create a separate case function for every case, and sometimes the test values are packed in separate variables, so I need a way to iterate through them. Parametrizing seems like a good solution, but then I'm getting the described problem.
Thanks!
The text was updated successfully, but these errors were encountered: