pytest-dev / pytest-order

pytest plugin that allows to customize the test execution order
https://pytest-order.readthedocs.io
Other
180 stars 14 forks source link

Ordering fixtures #98

Closed orsinium closed 9 months ago

orsinium commented 9 months ago

The pytest-order doesn't order fixtures. Would this feature be in the scope of the plugin?

To reproduce:

import pytest

@pytest.fixture
def fixt1():
    print(">>> fixt1")

@pytest.fixture
def fixt2(fixt1):
    print(">>> fixt2")

@pytest.mark.order("first")
@pytest.fixture
def fixt3():
    print(">>> fixt3")

def test_ex1(fixt2, fixt3):
    print(">>> test1")

Running:

python3 -m pytest -s

Output:

tests/test_example.py >>> fixt1
>>> fixt2
>>> fixt3
>>> test1

Expected:

tests/test_example.py >>> fixt3
>>> fixt1
>>> fixt2
>>> test1
mrbean-bremen commented 9 months ago

No, I don't think that this is in scope for this plugin. There is a defined order of fixtures, and to achieve the result you want you just have to reorder the fixtures in the test:

def test_ex1(fixt3, fixt2):
    print(">>> test1")

At least, that is what the pytest implementation does - the documentation actually gives no guarantees here... Anyway, even if it would make sense, this would be out of scope of this plugin. A separate plugin might make sense here.

mrbean-bremen commented 9 months ago

And after a quick search, there seems to already exist a plugin that does exactly that.

orsinium commented 9 months ago

Thank you! I'll try the plugin, it seems to work, at least in simple cases.