pytest
pytest copied to clipboard
Node ID parts vs. argument order with stacked parametrize / permutations
Someone in a pytest training of mine was surprised that:
import pytest
@pytest.mark.parametrize("a", ["a1", "a2"])
@pytest.mark.parametrize("b", ["b1", "b2"])
def test_permutations(a, b):
...
results in pytest collecting:
test_permutations[b1-a1]test_permutations[b1-a2]test_permutations[b2-a1]test_permutations[b2-a2]
Where the arguments are represented as b-a despite the test argument order being a, b.
I suspect this is because the decorators are applied from bottom to top (and indeed swapping them also generates "nicer" IDs). But I wonder if we could/should do better in cases where the parameters directly correspond to test arguments.
I agree it is a bit surprsing, I guess it is probably simple to just reverse the marks when evaluating them?
I would like to work on this as I noticed it has been under discussion since 2019 in "Parametrized params listed in reverse order in failed tests output" #5621
Let's close this as duplicate and introduce a opt in for declaration order that we will later turn into a opt out