Test name id generation defies common sense
See original GitHub issueWhat’s the problem this feature will solve?
Make test name generation intuitive and more flexible.
Describe the solution you’d like
Consider the following test cases:
@pytest.mark.parametrize(
"nums",
[[3, 1, 5, 4, 2], [2, 6, 4, 3, 1, 5], [1, 5, 6, 4, 3, 2]]
)
def test_cyclic_sort(nums):
pass
@pytest.mark.parametrize(
"nums, missing",
[([4, 0, 3, 1], 2)]
)
def test_find_missing_number(nums, missing):
pass
I’d like to customize the test names to include the input array only. Even though it’s not mentioned in the docs, turned out that the id func is called once for each argument; so if the same fn is used for both the above tests, for test_cyclic_sort
it’d get called with a list, whereas for test_find_missing_number
it’d first get called with a list, then with an int. It’s also not possible to ignore the second argument from test_find_missing_number
from being part of the test name.
This makes no sense whatsoever. The common sense implementation would be to pass all the args to the id func at once, either as a tuple or sequence. it also would likely be faster than calling the function once for each argument.
Additional context
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (7 by maintainers)
Agreed. If we agree passing one set of parameters (rather than every parameter individually) at once, that might also be a way forward to change this in a backwards-compatible way, something that @asarkar’s suggestions don’t address so far. Changing
ids
in a backwards-incompatible way is a no-go IMHO.Can you elaborate? Do you mean for the case where you have a single ID function which you want to reuse across different tests?
I don’t really see the problem - if we had a new
idfn
argument which takes a set of arguments (rather than a single one), rather than, say:you could always use a small wrapper like:
to get something very similar to the old behavior. The opposite isn’t possible.
I guess that would work, but I still think there’s value in the lightweight syntax of a
rather than:
Also, @asarkar, please dial it down a notch. “defies common sense”, “makes no sense whatsoever”, “is not really an outrageous ask IMO” etc. etc. isn’t very helpful.
@asarkar there is line between speaking the truth and being insufferable while speaking the truth, while giving you the benefit of doubt, in my impression you certainly spared no effort to talk down on us and that’s on you
and the CoC certainly has something about needlessly doing that, please check your attitude