no-migrations - Disable Django migrations When you alter your database schema, run pytest -create-db, to force Just run tests with pytest, on the first run the test database will beĬreated. Put -reuse-db in your default options (in your project’s pytest.ini file): Ī good way to use -reuse-db and -create-db can be: Example work flow with -reuse-db and -create-db. When used with -reuse-db, this option will re-create the database, create-db - force re creation of the test database Running without -reuse-db is also possible, since theĭatabase will automatically be re-created. The tests with -reuse-db -create-db to re-create the database according reuse-db will not pick up schema changes between test runs. This can be especially useful when running a few tests, when there are a lot This will allow much faster startup time for tests. The next time a test run is started with -reuse-db, the database will However, after the test run, the test database will not be removed. Using -reuse-db will create the test database in the same way as reuse-db - reuse the testing database between test runs django_db ( databases = ) def test_spam (): assert MyModel. Select using an argument to the django_db. Pytest-django also supports this style of tests, which you can Much slower to set up due to the required flushing of the database. The downside of this is that these tests are Testing transactions ĭjango itself has the TransactionTestCase whichĪllows you to test transactions and will flush the database between You to keep the test databases configured across different test runs. Pytest-django also caters for transaction test cases and allows Used for all subsequent tests and rolls back transactions, to isolate is_superuserīy default pytest-django will set up the Django databases theįirst time a test needs them. django_db def test_my_user ( self ): me = User. django_db class TestUsers : pytestmark = pytest.