Skip to content
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

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

Open
The-Compiler opened this issue Feb 13, 2025 · 1 comment
Labels
topic: parametrize related to @pytest.mark.parametrize

Comments

@The-Compiler
Copy link
Member

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 The-Compiler added the topic: parametrize related to @pytest.mark.parametrize label Feb 13, 2025
@nicoddemus
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: parametrize related to @pytest.mark.parametrize
Projects
None yet
Development

No branches or pull requests

2 participants