Skip to main content

A pytest plugin for preserving the order in which Django runs tests.

Project description

pytest-django advertises “easy switching.” While it’s true that existing unittest-style tests will work without any modifications, you may have problems switching if you depend on the order in which the Django test runner runs tests. This plugin helps preserve that order if you need it to run your tests.


The Django test runner gives priority to Django TestCase subclasses, executing them before other Django-based tests (e.g., TransactionTestCase) and any other unittest.TestCase tests. Put differently, Django runs tests which reset the database by rolling back a transaction before tests which reset the database by truncating all tables.

pytest-django doesn’t preserve this ordering out of the box. For more, see #214. This isn’t a problem if your project’s tests can run independently of each other, in any order. However, if your project’s tests rely on initial data populated via fixtures or migrations, tests which reset the database by rolling back a transaction must run before tests which reset the database by truncating all tables, thereby deleting any initial data. The serialized_rollback option can be used to deal with this issue within a TransactionTestCase, but it has no effect across distinct test cases; once you exit a TransactionTestCase, any initial data is gone.


This plugin supports Python 2.7, 3.5, and 3.6. Install with pip:

$ pip install pytest-django-ordering

You’re done! pytest will automatically find and integrate the plugin.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
pytest_django_ordering-1.0.1-py2.py3-none-any.whl (5.3 kB) Copy SHA256 hash SHA256 Wheel py2.py3
pytest-django-ordering-1.0.1.tar.gz (2.9 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page