You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently test-cases created by parametrize are automatically named by their values. If provided they will be named by their corresponding entry in the "ids" list. That is a way to manually override names for testcases which is useful when there are more complex cases which you want to describe to know what went wrong fast upon failure. Currently the code looks like that:
For small tests that is pretty good as everyone can count to two in this case.
However i often find myself in a situation where tests not only have 2 test cases but rather like 10 - 30 as there are probably some edge-cases which need to be considered. When having so much cases its hard to find the inputs with which a case failed due to you just get to see the case name, which you need to manually correlate with the argvalues by index, which is tedious.
Describe the solution you'd like
In my opinion that current implementation is working fine, however its somewhat inconvenient.
Therefore a object-based approach either for the argvalues or the whole decorator would be suitable to get rid of that issue:
@pytest.mark.parametrize( {"Testcase1": { # <- The name of the testcase"input": "some stuff", # <- The value for the parameter "input""expected": "my expected result", # <- The value for the parameter "expected" },"Testcase2": {"input": "some other stuff","expected": "my other expected result", }, })deftest_stuff(input, expected):
assertstuff(input) ==expected
alternatively if this would be too much of a change it could also be done like that:
@pytest.mark.parametrize( ["input", "expected"], {"Testcase1": ( # <- The name of the testcase"some stuff", # <- The value for the parameter "input""my expected result", # <- The value for the parameter "expected" ),"Testcase2": ("some other stuff","my other expected result", ), },)deftest_stuff(input, expected):
assertstuff(input) ==expected
to not introduce a breaking change that object could be handed over by a new parameter and making the current ones optional if the new one is set.
The text was updated successfully, but these errors were encountered:
irevolve
changed the title
Better Syntax for Parametrize named test cases
Better syntax for Parametrize's named test cases
Nov 26, 2024
What's the problem this feature will solve?
Currently test-cases created by parametrize are automatically named by their values. If provided they will be named by their corresponding entry in the "ids" list. That is a way to manually override names for testcases which is useful when there are more complex cases which you want to describe to know what went wrong fast upon failure. Currently the code looks like that:
For small tests that is pretty good as everyone can count to two in this case.
However i often find myself in a situation where tests not only have 2 test cases but rather like 10 - 30 as there are probably some edge-cases which need to be considered. When having so much cases its hard to find the inputs with which a case failed due to you just get to see the case name, which you need to manually correlate with the argvalues by index, which is tedious.
Describe the solution you'd like
In my opinion that current implementation is working fine, however its somewhat inconvenient.
Therefore a object-based approach either for the argvalues or the whole decorator would be suitable to get rid of that issue:
alternatively if this would be too much of a change it could also be done like that:
to not introduce a breaking change that object could be handed over by a new parameter and making the current ones optional if the new one is set.
The text was updated successfully, but these errors were encountered: