'pytest-ordering relative order not working?
I want to run some test by order, and i use pytest-ordering follow the offical article, but the order not change at all?
import pytest
@pytest.mark.run(after='test_second')
def test_third():
assert True
def test_second():
assert True
@pytest.mark.run(before='test_second')
def test_first():
assert True
It should be test_first, test_second, test_third order.
But The order don't change at all ???
E:\QT-learn>pytest -svv
============================================================================= test session starts =============================================================================
platform win32 -- Python 3.7.4, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- c:\users\jekoie\appdata\local\programs\python\python37-32\python.exe
cachedir: .pytest_cache
rootdir: E:\QT-learn, inifile: pytest.ini
plugins: ordering-0.6
collected 3 items
test_qt.py::test_third PASSED
test_qt.py::test_second PASSED
test_qt.py::test_first PASSED
============================================================================== 3 passed in 0.04s ==============================================================================
E:\QT-learn>
Solution 1:[1]
The documentation of pytest-ordering has a chapter named "Aspirational" with the following note:
This section is for functionality I’d like to implement. Documentation-driven design :)
The usage of before and after falls under this category.
You have to use the implemented functionality instead:
import pytest
@pytest.mark.run(order=3)
def test_third():
assert True
@pytest.mark.run(order=2)
def test_second():
assert True
@pytest.mark.run(order=1)
def test_first():
assert True
Note also that the method described in the documentation (using @pytest.mark.order1 etc.) does not work with the current version - the correct version is the one in the README. There is a pull request that would fix the documentation, but the project seems to be no longer maintained.
UPDATE:
pytest-order is a fork of pytest-ordering that implements this functionality (though beware the changed marker name). It is the successor of pytest-ordering which is no longer maintained.
Disclaimer: I'm the author of that fork.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
