From dd5f6d4c6b45612bd07bf344a7cb7fc7e9fbd5d7 Mon Sep 17 00:00:00 2001 From: bhelgs <33836927+bhelgs@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:21:43 -0400 Subject: [PATCH] add support for \ character in pytest temporary path - closes #982 --- newsfragments/982.misc.rst | 1 + pytest_postgresql/executor.py | 8 ++++---- tests/test_executor__bad_tmp.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 newsfragments/982.misc.rst create mode 100644 tests/test_executor__bad_tmp.py diff --git a/newsfragments/982.misc.rst b/newsfragments/982.misc.rst new file mode 100644 index 00000000..68346c3f --- /dev/null +++ b/newsfragments/982.misc.rst @@ -0,0 +1 @@ +add support for \\ character in pytest temporary path \ No newline at end of file diff --git a/pytest_postgresql/executor.py b/pytest_postgresql/executor.py index 25797492..ddcfbbed 100644 --- a/pytest_postgresql/executor.py +++ b/pytest_postgresql/executor.py @@ -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\d+(?:\.\d+)?)") @@ -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: diff --git a/tests/test_executor__bad_tmp.py b/tests/test_executor__bad_tmp.py new file mode 100644 index 00000000..4a018788 --- /dev/null +++ b/tests/test_executor__bad_tmp.py @@ -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