From ff0122acd6de47b43be6ebf251180261483b1588 Mon Sep 17 00:00:00 2001 From: Dani Hodovic Date: Wed, 13 Nov 2019 23:28:38 +0100 Subject: [PATCH] Use pytest-django --reuse-db for faster tests Pytest-django allows you to re-use database setups between tests for quicker test runs. This is especially useful for large projects with many migrations. For example, here's a project of mine with 40+ migrations: with --reuse-db ``` pytest --reuse-db 2.54s user 0.35s system 108% cpu 2.669 total ``` without --reuse-db ``` pytest 7.40s user 0.34s system 50% cpu 15.240 total ``` Caveat: if your model happens to change you need to manually --create-db to ensure migrations are applied. https://pytest-django.readthedocs.io/en/latest/database.html#reuse-db-reuse-the-testing-database-between-test-runs --- {{cookiecutter.project_slug}}/pytest.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/pytest.ini b/{{cookiecutter.project_slug}}/pytest.ini index 52b48ab0..e3b2248d 100644 --- a/{{cookiecutter.project_slug}}/pytest.ini +++ b/{{cookiecutter.project_slug}}/pytest.ini @@ -1,5 +1,5 @@ [pytest] -addopts = --ds=config.settings.test +addopts = --ds=config.settings.test --reuse-db python_files = tests.py test_*.py {%- if cookiecutter.js_task_runner != 'None' %} norecursedirs = node_modules