Skip to content

Commit 79659ae

Browse files
committed
should try to tear down db even if keeping it and db names need to be unique
1 parent fcdb2c4 commit 79659ae

File tree

7 files changed

+12
-6
lines changed

7 files changed

+12
-6
lines changed

pytest_django/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def django_db_setup(
104104
if not django_db_use_migrations:
105105
_disable_native_migrations()
106106

107-
if django_db_keepdb:
107+
if django_db_keepdb and not django_db_createdb:
108108
setup_databases_args["keepdb"] = True
109109

110110
with _django_db_blocker.unblock():

pytest_django_test/settings_base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import django
24

35
ROOT_URLCONF = "pytest_django_test.urls"
@@ -12,6 +14,10 @@
1214
STATIC_URL = "/static/"
1315
SECRET_KEY = "foobar"
1416

17+
# Used to construct unique test database names to allow detox to run multiple
18+
# versions at the same time
19+
db_suffix = "_%s" % os.getuid()
20+
1521
MIDDLEWARE = [
1622
"django.contrib.sessions.middleware.SessionMiddleware",
1723
"django.middleware.common.CommonMiddleware",

pytest_django_test/settings_mysql_innodb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
DATABASES = {
44
"default": {
55
"ENGINE": "django.db.backends.mysql",
6-
"NAME": "pytest_django_should_never_get_accessed",
6+
"NAME": "pytest_django_should_never_get_accessed" + db_suffix,
77
"HOST": "localhost",
88
"USER": "root",
99
"OPTIONS": {"init_command": "SET default_storage_engine=InnoDB"},

pytest_django_test/settings_mysql_myisam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
DATABASES = {
44
"default": {
55
"ENGINE": "django.db.backends.mysql",
6-
"NAME": "pytest_django_should_never_get_accessed",
6+
"NAME": "pytest_django_should_never_get_accessed" + db_suffix,
77
"HOST": "localhost",
88
"USER": "root",
99
"OPTIONS": {"init_command": "SET default_storage_engine=MyISAM"},

pytest_django_test/settings_postgres.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
DATABASES = {
1313
"default": {
1414
"ENGINE": "django.db.backends.postgresql_psycopg2",
15-
"NAME": "pytest_django_should_never_get_accessed",
15+
"NAME": "pytest_django_should_never_get_accessed" + db_suffix,
1616
"HOST": "localhost",
1717
"USER": "",
1818
}

pytest_django_test/settings_sqlite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
DATABASES = {
44
"default": {
55
"ENGINE": "django.db.backends.sqlite3",
6-
"NAME": "/should_not_be_accessed",
6+
"NAME": "/should_not_be_accessed" + db_suffix,
77
}
88
}

pytest_django_test/settings_sqlite_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
DATABASES = {
1212
"default": {
1313
"ENGINE": "django.db.backends.sqlite3",
14-
"NAME": "/pytest_django_should_never_get_accessed",
14+
"NAME": "/pytest_django_should_never_get_accessed" + db_suffix,
1515
"TEST": {"NAME": _filename},
1616
}
1717
}

0 commit comments

Comments
 (0)