tests: do not load fixture if keepdb is used and an user exists
This commit is contained in:
parent
e30a3e5112
commit
a14a7b1e7a
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue