Skip to content

Commit 5e53f0a

Browse files
committed
no need to modify it if it already equals that
1 parent a5b8acb commit 5e53f0a

10 files changed

+48
-44
lines changed

Diff for: .travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: python
22
dist: xenial
3+
cache: false
34

45
jobs:
56
fast_finish: true
@@ -97,7 +98,7 @@ install:
9798
- pip install tox==3.9.0
9899

99100
script:
100-
- tox
101+
- tox --force-dep "pytest@git+https://github.com/blueyed/pytest@fixture-stack#egg=pytest"
101102

102103
after_success:
103104
- |

Diff for: pytest_django/fixtures.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,34 @@
3636
def django_db_modify_db_settings_tox_suffix():
3737
skip_if_no_django()
3838

39-
tox_environment = os.getenv("TOX_PARALLEL_ENV")
40-
if tox_environment:
41-
# Put a suffix like _py27-django21 on tox workers
42-
_set_suffix_to_test_databases(suffix=tox_environment)
39+
return os.getenv("TOX_PARALLEL_ENV")
4340

4441

4542
@pytest.fixture(scope="session")
4643
def django_db_modify_db_settings_xdist_suffix(request):
4744
skip_if_no_django()
4845

49-
xdist_suffix = getattr(request.config, "slaveinput", {}).get("slaveid")
50-
if xdist_suffix:
51-
# Put a suffix like _gw0, _gw1 etc on xdist processes
52-
_set_suffix_to_test_databases(suffix=xdist_suffix)
46+
return getattr(request.config, "slaveinput", {}).get("slaveid")
5347

5448

5549
@pytest.fixture(scope="session")
5650
def django_db_modify_db_settings_parallel_suffix(
5751
django_db_modify_db_settings_tox_suffix,
58-
django_db_modify_db_settings_xdist_suffix,
52+
django_db_modify_db_settings_xdist_suffix
5953
):
6054
skip_if_no_django()
55+
xdist_worker = django_db_modify_db_settings_xdist_suffix
56+
tox_environment = django_db_modify_db_settings_tox_suffix
57+
suffix_parts = []
58+
if tox_environment:
59+
# Put a suffix like _py27-django21 on tox workers
60+
suffix_parts.append(tox_environment)
61+
if xdist_worker:
62+
# Put a suffix like _gw0, _gw1 etc on xdist processes
63+
suffix_parts.append(xdist_worker)
64+
suffix = "_".join(suffix_parts)
65+
if suffix:
66+
_set_suffix_to_test_databases(suffix=suffix)
6167

6268

6369
@pytest.fixture(scope="session")
@@ -182,10 +188,7 @@ def _set_suffix_to_test_databases(suffix):
182188
continue
183189

184190
db_settings.setdefault("TEST", {})
185-
test_db_name = test_name
186-
if not test_name.endswith("_{}".format(suffix)):
187-
test_db_name = "{}_{}".format(test_name, suffix)
188-
db_settings["TEST"]["NAME"] = test_db_name
191+
db_settings["TEST"]["NAME"] = "{}_{}".format(test_name, suffix)
189192

190193

191194
# ############### User visible fixtures ################

Diff for: pytest_django_test/settings_base.py

-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
31
import django
42

53
ROOT_URLCONF = "pytest_django_test.urls"
@@ -14,10 +12,6 @@
1412
STATIC_URL = "/static/"
1513
SECRET_KEY = "foobar"
1614

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-
2115
MIDDLEWARE = [
2216
"django.contrib.sessions.middleware.SessionMiddleware",
2317
"django.middleware.common.CommonMiddleware",

Diff for: pytest_django_test/settings_mysql_innodb.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from .settings_base import * # noqa: F403
1+
from .settings_base import * # noqa: F401 F403
22

33
DATABASES = {
44
"default": {
55
"ENGINE": "django.db.backends.mysql",
6-
"NAME": "pytest_django" + db_suffix, # noqa: F405
6+
"NAME": "pytest_django_should_never_get_accessed",
77
"HOST": "localhost",
88
"USER": "root",
99
"OPTIONS": {"init_command": "SET default_storage_engine=InnoDB"},

Diff for: pytest_django_test/settings_mysql_myisam.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from pytest_django_test.settings_base import * # noqa: F403
1+
from .settings_base import * # noqa: F401 F403
22

33
DATABASES = {
44
"default": {
55
"ENGINE": "django.db.backends.mysql",
6-
"NAME": "pytest_django" + db_suffix, # noqa: F405
6+
"NAME": "pytest_django_should_never_get_accessed",
77
"HOST": "localhost",
88
"USER": "root",
99
"OPTIONS": {"init_command": "SET default_storage_engine=MyISAM"},

Diff for: pytest_django_test/settings_postgres.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pytest_django_test.settings_base import * # noqa
1+
from .settings_base import * # noqa: F401 F403
22

33
# PyPy compatibility
44
try:
@@ -12,7 +12,7 @@
1212
DATABASES = {
1313
"default": {
1414
"ENGINE": "django.db.backends.postgresql_psycopg2",
15-
"NAME": "pytest_django" + db_suffix, # noqa
15+
"NAME": "pytest_django_should_never_get_accessed",
1616
"HOST": "localhost",
1717
"USER": "",
1818
}

Diff for: pytest_django_test/settings_sqlite.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .settings_base import * # noqa
1+
from .settings_base import * # noqa: F401 F403
22

33
DATABASES = {
44
"default": {

Diff for: pytest_django_test/settings_sqlite_file.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import tempfile
22

3-
from pytest_django_test.settings_base import * # noqa
3+
from .settings_base import * # noqa: F401 F403
44

55
# This is a SQLite configuration, which uses a file based database for
66
# tests (via setting TEST_NAME / TEST['NAME']).
@@ -11,7 +11,7 @@
1111
DATABASES = {
1212
"default": {
1313
"ENGINE": "django.db.backends.sqlite3",
14-
"NAME": "/should_never_be_accessed",
14+
"NAME": "/pytest_django_should_never_get_accessed",
1515
"TEST": {"NAME": _filename},
1616
}
1717
}

Diff for: tests/test_db_setup.py

+19-15
Original file line numberDiff line numberDiff line change
@@ -159,32 +159,34 @@ def test_xdist_with_reuse(django_testdir):
159159
160160
from .app.models import Item
161161
162-
def _check(settings):
162+
def _check(settings, worker_id):
163163
# Make sure that the database name looks correct
164164
db_name = settings.DATABASES['default']['NAME']
165-
assert db_name.endswith('_gw0') or db_name.endswith('_gw1')
166-
165+
assert db_name == (
166+
'test_pytest_django_should_never_get_accessed_inner_inner_{}'
167+
.format(worker_id)
168+
)
167169
assert Item.objects.count() == 0
168170
Item.objects.create(name='foo')
169171
assert Item.objects.count() == 1
170172
171173
172174
@pytest.mark.django_db
173-
def test_a(settings):
174-
_check(settings)
175+
def test_a(settings, worker_id):
176+
_check(settings, worker_id)
175177
176178
177179
@pytest.mark.django_db
178-
def test_b(settings):
179-
_check(settings)
180+
def test_b(settings, worker_id):
181+
_check(settings, worker_id)
180182
181183
@pytest.mark.django_db
182-
def test_c(settings):
183-
_check(settings)
184+
def test_c(settings, worker_id):
185+
_check(settings, worker_id)
184186
185187
@pytest.mark.django_db
186-
def test_d(settings):
187-
_check(settings)
188+
def test_d(settings, worker_id):
189+
_check(settings, worker_id)
188190
"""
189191
)
190192

@@ -270,7 +272,7 @@ def test_sqlite_database_renamed(self, django_testdir):
270272
from django.db import connections
271273
272274
@pytest.mark.django_db
273-
def test_a():
275+
def test_a(worker_id):
274276
(conn_db2, conn_default) = sorted(
275277
connections.all(),
276278
key=lambda conn: conn.alias,
@@ -288,7 +290,7 @@ def test_a():
288290
289291
assert conn_db2.vendor == 'sqlite'
290292
db_name = conn_db2.creation._get_test_db_name()
291-
assert db_name.startswith('test_custom_db_name_gw')
293+
assert db_name == 'test_custom_db_name_{}'.format(worker_id)
292294
"""
293295
)
294296

@@ -377,13 +379,15 @@ def test_db_with_tox_suffix(self, django_testdir, monkeypatch):
377379
from django.db import connections
378380
379381
@pytest.mark.django_db
380-
def test_inner():
382+
def test_inner(worker_id):
381383
382384
(conn, ) = connections.all()
383385
384386
assert conn.vendor == 'sqlite'
385387
db_name = conn.creation._get_test_db_name()
386-
assert db_name.startswith('test_custom_db_name_py37-django22_gw')
388+
assert db_name == 'test_custom_db_name_py37-django22_{}'.format(
389+
worker_id,
390+
)
387391
"""
388392
)
389393

Diff for: tox.ini

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ deps =
2727
postgres: psycopg2-binary
2828
coverage: coverage-enable-subprocess
2929

30+
pytest
31+
3032
pytest41: pytest>=4.1,<4.2
3133
pytest41: attrs==17.4.0
3234
xdist: pytest-xdist>=1.15

0 commit comments

Comments
 (0)