Skip to content

Commit

Permalink
Pass locale environment to initdb and pg_ctl
Browse files Browse the repository at this point in the history
We now the environment dict containing locale settings to calls of
'initdb' and 'pg_ctl'. This is so as to avoid initdb to pick the locale
setting of its execution environment [1] which, when not an English one,
will then make the checks in PostgreSQLExecutor.running() (where the
message "pg_ctl: server is running" is expected) fail.

Fix #315.

[1]: https://www.postgresql.org/docs/current/locale.html
  • Loading branch information
dlax committed Sep 28, 2020
1 parent 035f90c commit 9f9ac80
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/pytest_postgresql/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def init_directory(self):
self.clean_directory()
init_directory = [self.executable, 'initdb', '--pgdata', self.datadir]
options = ['--username=%s' % self.user]
env = self._envvars.copy()

if self.password:
with tempfile.NamedTemporaryFile() as password_file:
Expand All @@ -150,11 +151,11 @@ def init_directory(self):
password_file.write(password)
password_file.flush()
init_directory += ['-o', ' '.join(options)]
subprocess.check_output(init_directory)
subprocess.check_output(init_directory, env=env)
else:
options += ['--auth=trust']
init_directory += ['-o', ' '.join(options)]
subprocess.check_output(init_directory)
subprocess.check_output(init_directory, env=env)

self._directory_initialised = True

Expand Down Expand Up @@ -202,6 +203,7 @@ def running(self):
pg_ctl=self.executable,
datadir=self.datadir
),
env=self._envvars.copy(),
shell=True
).decode('utf-8')
except subprocess.CalledProcessError as ex:
Expand Down

0 comments on commit 9f9ac80

Please sign in to comment.