Skip to content

How do I order a module to be run last in a session-scope of multiple directories? #69

Answered by mrbean-bremen
mchesler613 asked this question in Q&A
Discussion options

You must be logged in to vote

If you just want to order this one module, and not order any tests inside it, you can add an order marker to the last test in that module (either pytest.mark.order(-1) or pytest.mark.order("last")):

directory_one/test_module2.py

import pytest

def test_1():
    pass

def test_2():
    pass

@pytest.mark.order(-1)
def test_3():
    pass

and use the module order group scope (see also the last example in the documentation):

$ python -m pytest --order-group-scope=module

If you always want to order module-wise, you may add this option to pytest.ini:

pytest.ini

[pytest]
; order tests first inside modules, order whole modules afterwards 
addopts = --order-group-scope=module

If you don't add any…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mchesler613
Comment options

@mrbean-bremen
Comment options

Answer selected by mchesler613
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants