Skip to content

Commit

Permalink
add support for \ character in pytest temporary path - closes Clearco…
Browse files Browse the repository at this point in the history
  • Loading branch information
bhelgs committed Jul 16, 2024
1 parent b87fdc3 commit dd5f6d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions newsfragments/982.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add support for \\ character in pytest temporary path
8 changes: 4 additions & 4 deletions pytest_postgresql/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class PostgreSQLExecutor(TCPExecutor):
"""

BASE_PROC_START_COMMAND = (
"{executable} start -D {datadir} "
'{executable} start -D "{datadir}" '
"-o \"-F -p {port} -c log_destination='stderr' "
"-c logging_collector=off "
"-c unix_socket_directories='{unixsocketdir}' {postgres_options}\" "
"-l {logfile} {startparams}"
'-l "{logfile}" {startparams}'
)

VERSION_RE = re.compile(r".* (?P<version>\d+(?:\.\d+)?)")
Expand Down Expand Up @@ -214,13 +214,13 @@ def running(self) -> bool:
"""Check if server is running."""
if not os.path.exists(self.datadir):
return False
status_code = subprocess.getstatusoutput(f"{self.executable} status -D {self.datadir}")[0]
status_code = subprocess.getstatusoutput(f'{self.executable} status -D "{self.datadir}"')[0]
return status_code == 0

def stop(self: T, sig: Optional[int] = None, exp_sig: Optional[int] = None) -> T:
"""Issue a stop request to executable."""
subprocess.check_output(
f"{self.executable} stop -D {self.datadir} -m f",
f'{self.executable} stop -D "{self.datadir}" -m f',
shell=True,
)
try:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_executor__bad_tmp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Union

import pytest
import tests.test_postgresql


@pytest.fixture(scope="session")
def tmp_path_factory(tmp_path_factory: Union[pytest.TempPathFactory]):
r"""overrides the pytest factory to include the \ character"""
with tmp_path_factory.mktemp(r"bad\path") as tmp:
pytest.TempPathFactory(tmp, retention_count=0, retention_policy="none", trace=None)


# we want to redo this test but with the custom tmp_path_factory (\)
test_postgresql_proc__bad_path = tests.test_postgresql.test_postgresql_proc

0 comments on commit dd5f6d4

Please sign in to comment.