File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 1- import os
21import tempfile
32import uuid
43
54import pytest
65
6+ from django .conf import settings
77from django .contrib .postgres .signals import register_type_handlers
88from django .db import connection
99
@@ -35,11 +35,24 @@ def django_db_setup(django_db_setup, django_db_blocker):
3535 with django_db_blocker .unblock ():
3636 qn = connection .ops .quote_name
3737
38- with tempfile .TemporaryDirectory () as temp_dir :
39- if not os .path .exists (temp_dir ):
40- os .makedirs (temp_dir )
38+ db_hostname = settings .DATABASES [connection .alias ]["HOST" ]
4139
40+ with tempfile .TemporaryDirectory () as temp_dir :
4241 with connection .cursor () as cursor :
42+ # If the database is remote, like in a CI environment, make
43+ # sure the temporary directory exists in the container
44+ # that PostgreSQL is running.
45+ #
46+ # Note that this only typically works in CI environments
47+ # where we have utter control to execute arbitary commands.
48+ if db_hostname and db_hostname not in (
49+ "127.0.0.1" ,
50+ "localhost" ,
51+ ):
52+ cursor .execute (
53+ f"COPY (select 1) TO PROGRAM 'mkdir --mode=777 -p { temp_dir } '"
54+ )
55+
4356 cursor .execute (
4457 f"CREATE TABLESPACE { qn (custom_tablespace_name )} LOCATION %s" ,
4558 (temp_dir ,),
You can’t perform that action at this time.
0 commit comments