pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Node ID parts vs. argument order with stacked parametrize / permutations

Open The-Compiler opened this issue 9 months ago • 3 comments

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.

The-Compiler avatar Feb 13 '25 17:02 The-Compiler

I agree it is a bit surprsing, I guess it is probably simple to just reverse the marks when evaluating them?

nicoddemus avatar Feb 14 '25 11:02 nicoddemus

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

DionisiaK4 avatar Apr 27 '25 13:04 DionisiaK4

Let's close this as duplicate and introduce a opt in for declaration order that we will later turn into a opt out

RonnyPfannschmidt avatar Apr 27 '25 14:04 RonnyPfannschmidt