tests: do not load fixture if keepdb is used and an user exists

This commit is contained in:
Benjamin Dauvergne 2021-11-25 23:03:56 +01:00
parent e30a3e5112
commit a14a7b1e7a
1 changed files with 10 additions and 11 deletions

View File

@ -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