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

8.0.0 reverses order of parametrize when calling individual tests #11937

Closed
4 tasks done
okken opened this issue Feb 5, 2024 · 4 comments · Fixed by #11957
Closed
4 tasks done

8.0.0 reverses order of parametrize when calling individual tests #11937

okken opened this issue Feb 5, 2024 · 4 comments · Fixed by #11957
Labels
topic: collection related to the collection phase type: bug problem that needs to be addressed type: regression indicates a problem that was introduced in a release which was working previously

Comments

@okken
Copy link
Contributor

okken commented Feb 5, 2024

Summary
Marking a test with @pytest.mark.parametrize('i', [1, 2, 3, 4]), I expect the test to run 1, 2, 3, 4.
As a file, pytest does this as expected.
Running individual tests, though, results in 4, 3, 2, 1.
This is surprising behavior and new to 8.0.0.

(foo) $ pytest test_param.py::test_param -v
...
platform win32 -- Python 3.11.7, pytest-8.0.0, ...
...
test_param.py::test_param[4] PASSED                                      [ 25%]
test_param.py::test_param[3] PASSED                                      [ 50%]
test_param.py::test_param[2] PASSED                                      [ 75%]
test_param.py::test_param[1] PASSED                                      [100%]
...

Version 7.4.4 runs the test cases in the expected 1, 2, 3, 4 order.

(foo) $ pytest test_param.py::test_param -v
...
platform win32 -- Python 3.11.7, pytest-7.4.4, ...
...
test_param.py::test_param[1] PASSED                                      [ 25%]
test_param.py::test_param[2] PASSED                                      [ 50%]
test_param.py::test_param[3] PASSED                                      [ 75%]
test_param.py::test_param[4] PASSED                                      [100%]
...

Detail

  • a detailed description of the bug or problem you are having
    When running individual parametrized tests, the order is reversed.
    This is new in 8.0.0, and not the case in 7.4.4
    Since 8.0.0 doesn't guarantee backward compatibility, I'm not sure if this is a bug or a feature. :)
    But I didn't see it in the notes, so I'm guessing this is an unintended change, and it is an unexpected, surprising behavior.

  • output of pip list from the virtual environment you are using

$ pip list
Package    Version
---------- -------
colorama   0.4.6
iniconfig  2.0.0
packaging  23.2
pip        23.3.1
pluggy     1.3.0
pytest     8.0.0
setuptools 65.5.0
  • pytest and operating system versions

platform win32 -- Python 3.11.7, pytest-8.0.0, pluggy-1.3.0

  • minimal example if possible
$ cat test_param.py
import pytest

@pytest.mark.parametrize('i', [1, 2, 3, 4])
def test_param(i):
    ...

Output from 8.0.0, shows expected 1,2,3,4 order with file invocation, but reverse order with individual test, 4, 3, 2, 1

(foo) $ pytest test_param.py -v
============================= test session starts =============================
platform win32 -- Python 3.11.7, pytest-8.0.0, pluggy-1.3.0 -- C:\Users\okken\projects\foo\venv\Scripts\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\okken\projects\foo
configfile: pytest.ini
collecting ... collected 4 items

test_param.py::test_param[1] PASSED                                      [ 25%]
test_param.py::test_param[2] PASSED                                      [ 50%]
test_param.py::test_param[3] PASSED                                      [ 75%]
test_param.py::test_param[4] PASSED                                      [100%]

============================== 4 passed in 0.01s ==============================
(foo) $ pytest test_param.py::test_param -v
============================= test session starts =============================
platform win32 -- Python 3.11.7, pytest-8.0.0, pluggy-1.3.0 -- C:\Users\okken\projects\foo\venv\Scripts\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\okken\projects\foo
configfile: pytest.ini
collecting ... collected 4 items

test_param.py::test_param[4] PASSED                                      [ 25%]
test_param.py::test_param[3] PASSED                                      [ 50%]
test_param.py::test_param[2] PASSED                                      [ 75%]
test_param.py::test_param[1] PASSED                                      [100%]

============================== 4 passed in 0.02s ==============================

Output from 7.4.4, shows expected 1,2,3,4 order with both file and individual test invocation.

(foo) $ pytest test_param.py -v
============================= test session starts =============================
platform win32 -- Python 3.11.7, pytest-7.4.4, pluggy-1.3.0 -- C:\Users\okken\projects\foo\venv\Scripts\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\okken\projects\foo
configfile: pytest.ini
collecting ... collected 4 items

test_param.py::test_param[1] PASSED                                      [ 25%]
test_param.py::test_param[2] PASSED                                      [ 50%]
test_param.py::test_param[3] PASSED                                      [ 75%]
test_param.py::test_param[4] PASSED                                      [100%]

============================== 4 passed in 0.02s ==============================
(foo) $ pytest test_param.py::test_param -v
============================= test session starts =============================
platform win32 -- Python 3.11.7, pytest-7.4.4, pluggy-1.3.0 -- C:\Users\okken\projects\foo\venv\Scripts\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\okken\projects\foo
configfile: pytest.ini
collecting ... collected 4 items

test_param.py::test_param[1] PASSED                                      [ 25%]
test_param.py::test_param[2] PASSED                                      [ 50%]
test_param.py::test_param[3] PASSED                                      [ 75%]
test_param.py::test_param[4] PASSED                                      [100%]

============================== 4 passed in 0.00s ==============================
@The-Compiler
Copy link
Member

Bisected to 385796b:

cc @bluetech

@bluetech bluetech added type: bug problem that needs to be addressed topic: collection related to the collection phase type: regression indicates a problem that was introduced in a release which was working previously labels Feb 8, 2024
bluetech added a commit to bluetech/pytest that referenced this issue Feb 9, 2024
Since we're working with a stack (last in first out), we need to append
to it in reverse to preserve the order when popped.

Fix pytest-dev#11937.
@bluetech
Copy link
Member

bluetech commented Feb 9, 2024

Thanks @okken for the clear report and @The-Compiler for bisecting. Submitted a fix in #11957.

@okken
Copy link
Contributor Author

okken commented Feb 9, 2024

@The-Compiler I really need to lean on bisect more often. You're an inspiration.
@bluetech That's awesome that you found a fix so quickly. You rock.

@The-Compiler
Copy link
Member

Hah, the moment I found out about git bisect, it felt like magic!

For reference, for something like this, what I do is something like:

  • Make sure I did a pip install -e .
  • git bisect start
  • git checkout 8.0.0 and make sure I can repro
  • git bisect bad
  • git checkout 7.4.4 and make sure it works fine
  • git bisect good
  • Follow instructions and git bisect good or git bisect bad as necessary.

After the initial range, I needed to test < 10 times to find the culprit, so it's something that can usually be done in minutes once there is a nice fast reproducer.

flying-sheep pushed a commit to flying-sheep/pytest that referenced this issue Apr 9, 2024
Since we're working with a stack (last in first out), we need to append
to it in reverse to preserve the order when popped.

Fix pytest-dev#11937.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase type: bug problem that needs to be addressed type: regression indicates a problem that was introduced in a release which was working previously
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants