Created
August 16, 2013 12:56
-
-
Save witsch/6249692 to your computer and use it in GitHub Desktop.
example pytest session fixture reordering the tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pytest import fixture, Class | |
@fixture(scope="session", autouse=True) | |
def sort_tests_by_class_name(request): | |
session = request.node | |
key = lambda item: item.getparent(Class).obj.__name__ | |
session.items[:] = sorted(session.items, key=key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the ordering is done by class name here, but
__name__
could simply be replaced bylayer
. also see http://pytest.org/latest/example/special.html for more information.the above file needs to be put into
conftest.py
in your tests directory. the altered ordering can be seen when runningpy.test -v
...