From a14a7b1e7a14ca716777eea3c138f67b55c95f53 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 25 Nov 2021 23:03:56 +0100 Subject: [PATCH] tests: do not load fixture if keepdb is used and an user exists --- tests/conftest.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index ef37809..c8e34bc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -23,19 +23,18 @@ DATA = ["tests/fixture.json"] @pytest.fixture(scope="session") -def django_db_setup(django_db_setup, django_db_blocker): - print('django_db_setup start') +def django_db_setup(django_db_setup, django_db_blocker, django_db_keepdb, django_db_createdb): with django_db_blocker.unblock(): - for data in DATA: - call_command("loaddata", data) - admin, _ = User.objects.update_or_create( - username="admin", - defaults=dict(email="admin@example.com", is_superuser=True, is_staff=True), - ) - admin.set_password("admin") - admin.save() + if not django_db_keepdb or django_db_createdb or User.objects.count() == 0: + for data in DATA: + call_command("loaddata", data) + admin, _ = User.objects.update_or_create( + username="admin", + defaults=dict(email="admin@example.com", is_superuser=True, is_staff=True), + ) + admin.set_password("admin") + admin.save() yield - print('django_db_setup stop') @pytest.fixture