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

change param_index if param is pseudofixturedef #12082

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ShurikMen
Copy link
Contributor

fix #12008

for param_index, (param_id, param_set) in enumerate(
zip(ids, parametersets)
):
if name2pseudofixturedef:
param_index = callspec_index + param_index
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we have

Suggested change
param_index = callspec_index + param_index
param_index = callspec_index * len(parametersets) + param_index

? Because currently some callspecs would have arguments with the same param index but different param values. For example, test1[1-b] and test1[2-a] whose arg2 param index is 1. However this doesn't show up in this test. In

def test_multi_parametrize_reordering(self, pytester: Pytester) -> None:
        pytester.makepyfile(
            """
            import pytest

            @pytest.mark.parametrize("arg2", ['a', 'b', 'c'], scope='class')
            @pytest.mark.parametrize("arg1", [1, 2], scope='class')
            class TestClass:
                def test1(self, arg1, arg2):
                    pass

                def test2(self, arg1, arg2):
                    pass
        """
        )
        result = pytester.runpytest("--collect-only")
        result.stdout.re_match_lines(
            [
                r"      <Function test1\[1-a\]>",
                r"      <Function test2\[1-a\]>",
                r"      <Function test1\[1-b\]>",
                r"      <Function test2\[1-b\]>",
                r"      <Function test1\[1-c\]>",
                r"      <Function test2\[1-c\]>",
                r"      <Function test1\[2-a\]>",
                r"      <Function test2\[2-a\]>",
                r"      <Function test1\[2-b\]>",
                r"      <Function test2\[2-b\]>",
                r"      <Function test1\[2-c\]>",
                r"      <Function test2\[2-c\]>",
            ]
        )

it raises error. The test output would be:

<Dir test_multi_parametrize_reordering0>
  <Module test_multi_parametrize_reordering.py>
    <Class TestClass>
      <Function test1[1-a]>
      <Function test2[1-a]>
      <Function test1[1-b]>
      <Function test2[1-b]>
      <Function test1[2-a]>
      <Function test2[2-a]>
      <Function test1[2-b]>
      <Function test2[2-b]>
      <Function test1[1-c]>
      <Function test2[1-c]>
      <Function test1[2-c]>
      <Function test2[2-c]>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also suggest removing the "if name2pseudofixturedef" check so that sorting parameterized tests through a marker and through a fixture works the same way.
But then it is necessary to correct the tests test_module_parametrized_ordering and test_dynamic_parametrized_ordering along the way

RonnyPfannschmidt pushed a commit that referenced this pull request Aug 11, 2024
In #11220, an unintended change in reordering was introduced by changing the way indices were assigned to direct params. This PR reverts that change and reduces #11220 changes to just refactors.

After this PR we could safely decide on the solutions discussed in #12008, i.e. #12082 or the one initially introduced in #11220 .

Fixes #12008

Co-authored-by: Bruno Oliveira <[email protected]>
Co-authored-by: Bruno Oliveira <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pytest 8.0 sorting tests with multiple parameterization is broken
2 participants