Pytest-order breaks the fixture scope for parametrized fixtures #49
-
This came up in a StackOverflow question. In the following code: @pytest.fixture(params=[1, 2], scope="class")
def number(request):
print(f"setup number {request.param}")
yield request.param
print(f"teardown number {request.param}")
@pytest.mark.usefixtures("number")
class TestClass:
@pytest.mark.order(2)
def test1(self):
pass
@pytest.mark.order(1)
def test2(self):
pass the test fixture will be called twice instead of once for each parameter. Removing the order markers fixes this. I'm not entirely sure how the correct behavior should be. Without the ordering, with the class scope the tests are reordered so that all tests with the same parameter are run consecutively - this allows the class scope to work. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Copying the slightly adapted answer from Stack Overflow here: This is actually expected behavior and not a bug, because the tests are explicitely ordered, and this ordering is done after any initial ordering due to the fixture usage. There is a possibility to change this behavior, if using the option --indulgent-ordering. This changes the sequence of the ordering, so that the tests are first ordered by the plugin, and afterwards by the fixture. Here is the behavior without the option:
With the
which makes it possible for the fixture to properly work as a class-scoped fixture. As usually, you can add the option to your
|
Beta Was this translation helpful? Give feedback.
Copying the slightly adapted answer from Stack Overflow here:
This is actually expected behavior and not a bug, because the tests are explicitely ordered, and this ordering is done after any initial ordering due to the fixture usage.
There is a possibility to change this behavior, if using the option --indulgent-ordering. This changes the sequence of the ordering, so that the tests are first ordered by the plugin, and afterwards by the fixture.
Here is the behavior without the option:
W…