Skip to content

Commit 8e9772b

Browse files
committed
fixup: pass template with executor
1 parent a4eb403 commit 8e9772b

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

pytest_postgresql/executor.py

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def __init__(
6969
logfile: str,
7070
startparams: str,
7171
dbname: str,
72+
template_dbname: str,
7273
shell: bool = False,
7374
timeout: Optional[int] = 60,
7475
sleep: float = 0.1,
@@ -102,6 +103,7 @@ def __init__(
102103
self.user = user
103104
self.password = password
104105
self.dbname = dbname
106+
self.template_dbname = template_dbname
105107
self.options = options
106108
self.datadir = datadir
107109
self.unixsocketdir = unixsocketdir

pytest_postgresql/executor_noop.py

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(
3737
user: str,
3838
options: str,
3939
dbname: str,
40+
template_dbname: str,
4041
password: Optional[str] = None,
4142
):
4243
"""Initialize nooperator executor mock.
@@ -54,6 +55,7 @@ def __init__(
5455
self.options = options
5556
self.password = password
5657
self.dbname = dbname
58+
self.template_dbname = template_dbname
5759
self._version: Any = None
5860

5961
@property

pytest_postgresql/factories/client.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ def postgresql_factory(request: FixtureRequest) -> Iterator[Connection]:
6363
pg_user = proc_fixture.user
6464
pg_password = proc_fixture.password
6565
pg_options = proc_fixture.options
66-
pg_db = dbname
67-
pg_template = None
68-
if not dbname:
69-
pg_db = proc_fixture.dbname
70-
pg_template = f"{pg_db}_tmpl"
66+
pg_db = dbname or proc_fixture.dbname
7167
pg_load = load or []
7268
if pg_load:
7369
warnings.warn(
@@ -84,7 +80,7 @@ def postgresql_factory(request: FixtureRequest) -> Iterator[Connection]:
8480
host=pg_host,
8581
port=pg_port,
8682
dbname=pg_db,
87-
template_dbname=pg_template,
83+
template_dbname=proc_fixture.template_dbname,
8884
version=proc_fixture.version,
8985
password=pg_password,
9086
isolation_level=isolation_level,

pytest_postgresql/factories/noprocess.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ def postgresql_noproc_fixture(request: FixtureRequest) -> Iterator[NoopExecutor]
7979
user=pg_user,
8080
password=pg_password,
8181
dbname=pg_dbname,
82+
template_dbname=f"{pg_dbname}_tmpl",
8283
options=pg_options,
8384
)
84-
template_dbname = f"{noop_exec.dbname}_tmpl"
8585
with DatabaseJanitor(
8686
user=noop_exec.user,
8787
host=noop_exec.host,
8888
port=noop_exec.port,
89-
template_dbname=template_dbname,
89+
template_dbname=noop_exec.template_dbname,
9090
version=noop_exec.version,
9191
password=noop_exec.password,
9292
) as janitor:

pytest_postgresql/factories/process.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def postgresql_proc_fixture(
126126
user=user or config["user"],
127127
password=password or config["password"],
128128
dbname=pg_dbname,
129+
template_dbname=f"{pg_dbname}_tmpl",
129130
options=options or config["options"],
130131
datadir=str(datadir),
131132
unixsocketdir=unixsocketdir or config["unixsocketdir"],
@@ -136,12 +137,11 @@ def postgresql_proc_fixture(
136137
# start server
137138
with postgresql_executor:
138139
postgresql_executor.wait_for_postgres()
139-
template_dbname = f"{postgresql_executor.dbname}_tmpl"
140140
with DatabaseJanitor(
141141
user=postgresql_executor.user,
142142
host=postgresql_executor.host,
143143
port=postgresql_executor.port,
144-
template_dbname=template_dbname,
144+
template_dbname=postgresql_executor.template_dbname,
145145
version=postgresql_executor.version,
146146
password=postgresql_executor.password,
147147
) as janitor:

pytest_postgresql/janitor.py

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(
3939
:param host: postgresql host
4040
:param port: postgresql port
4141
:param dbname: database name
42+
:param dbname: template database name
4243
:param version: postgresql version number
4344
:param password: optional postgresql password
4445
:param isolation_level: optional postgresql isolation level

0 commit comments

Comments
 (0)