Skip to content

Commit f59417a

Browse files
committed
Use explicit flag to detect database in container during tests
1 parent 7eccfd3 commit f59417a

File tree

3 files changed

+4
-12
lines changed

3 files changed

+4
-12
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ commands:
4545
command: tox --listenvs | grep ^py<< parameters.pyversion >> | circleci tests split | xargs -n 1 tox -e
4646
environment:
4747
DATABASE_URL: 'postgres://psqlextra:psqlextra@localhost:5432/psqlextra'
48+
DATABASE_IN_CONTAINER: 'true'
4849

4950
jobs:
5051
test-python36:

settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ def _parse_db_url(url: str):
4343

4444
USE_TZ = True
4545
TIME_ZONE = 'UTC'
46+
47+
DATABASE_IN_CONTAINER = os.environ.get('DATABASE_IN_CONTAINER') == 'true'

tests/conftest.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ def django_db_setup(django_db_setup, django_db_blocker):
3434

3535
with django_db_blocker.unblock():
3636
qn = connection.ops.quote_name
37-
38-
db_user = settings.DATABASES[connection.alias]["USER"]
39-
db_hostname = settings.DATABASES[connection.alias]["HOST"]
40-
4137
with tempfile.TemporaryDirectory() as temp_dir:
4238
with connection.cursor() as cursor:
4339
# If the database is remote, like in a CI environment, make
@@ -46,14 +42,7 @@ def django_db_setup(django_db_setup, django_db_blocker):
4642
#
4743
# Note that this only typically works in CI environments
4844
# where we have utter control to execute arbitary commands.
49-
if db_user or (
50-
db_hostname
51-
and db_hostname
52-
not in (
53-
"127.0.0.1",
54-
"localhost",
55-
)
56-
):
45+
if settings.DATABASE_IN_CONTAINER:
5746
cursor.execute(
5847
f"COPY (select 1) TO PROGRAM 'mkdir --mode=777 -p {temp_dir}'"
5948
)

0 commit comments

Comments
 (0)