Can I do order annotations at the module level? #124
-
All I need is for one particular module to run last is this possible? I didn't see this anywhere in the docs. Want I would want is to be able to set the order at the top of the pytest file. For example I'd just set |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
This is not directly possible. A marker has always to be set to a test or test class, and at least to my knowledge there is no easy way to set a marker to a whole module. There is a workaround, however. That ensures that the tests inside the module are not reordered, as they are already ordered correctly, and the modules are afterwards ordered, so that the module with the marker is ordered last: test_one.py def test_1():
pass
def test_2():
pass
def test_3():
pass test_two.py def test_1():
pass
def test_2():
pass
def test_3():
pass test_last.py import pytest
def test_1():
pass
def test_2():
pass
@pytest.mark.order(-1)
def test_3():
pass
(without that, |
Beta Was this translation helpful? Give feedback.
-
I think you can use a global "pytestmark" variable? pytestmark = [pytest.mark.order(1)] cf https://docs.pytest.org/en/stable/example/markers.html#marking-whole-classes-or-modules |
Beta Was this translation helpful? Give feedback.
Thanks, good point! I hadn't thought about this at the time.
What this does is essentially putting the marker on all tests in the module, and as the order is preserved for similar markers this will also work.
You still have to use
--order-group-scope=module
as mentioned, but you can change test_last.py to:so there is no need to put the marker onto the last test.