Skip to content

Commit 14e3f3e

Browse files
committed
return temporary dir object, not just the string, so that it doesnt get garbage collected early.
1 parent 6b53982 commit 14e3f3e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

postgresql/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ def f(cmdline):
3434

3535
def setup(pgdata=None, log="db_test.log", user="postgres"):
3636
if pgdata is None:
37-
pgdata = TemporaryDirectory().name
37+
pgdata = TemporaryDirectory()
3838

3939
log = Path(log)
4040
try:
4141
log.unlink()
4242
except FileNotFoundError:
4343
pass
4444

45-
initdb(f"-D {pgdata} --auth-local=trust --no-sync -U postgres")
46-
pg_ctl(f'-D {pgdata} -o "-k {pgdata} -h \\"\\"" -l {log} start')
45+
initdb(f"-D {pgdata.name} --auth-local=trust --no-sync -U postgres")
46+
pg_ctl(f'-D {pgdata.name} -o "-k {pgdata.name} -h \\"\\"" -l {log} start')
4747
sleep(3)
48-
con_str = f"host={pgdata} user={user}"
48+
con_str = f"host={pgdata.name} user={user}"
4949
return pgdata, con_str
5050

5151

5252
def teardown(pgdata):
53-
msg = pg_ctl(f"-D {pgdata} stop")
54-
shutil.rmtree(pgdata)
53+
msg = pg_ctl(f"-D {pgdata.name} stop")
54+
pgdata.cleanup()
5555
return msg
5656

5757

0 commit comments

Comments
 (0)