Skip to content

Instantly share code, notes, and snippets.

@witsch
Created August 16, 2013 12:56
Show Gist options
  • Save witsch/6249692 to your computer and use it in GitHub Desktop.
Save witsch/6249692 to your computer and use it in GitHub Desktop.
example pytest session fixture reordering the tests
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)
@witsch
Copy link
Author

witsch commented Aug 16, 2013

the ordering is done by class name here, but __name__ could simply be replaced by layer. 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 running py.test -v...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment