-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
base: main
Are you sure you want to change the base?
Conversation
src/_pytest/python.py
Outdated
for param_index, (param_id, param_set) in enumerate( | ||
zip(ids, parametersets) | ||
): | ||
if name2pseudofixturedef: | ||
param_index = callspec_index + param_index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we have
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]>
There was a problem hiding this comment.
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
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]>
fix #12008