Skip to content

Commit d530337

Browse files
committed
Fix output leakage, cross-platform test coverage, and Windows start env/posix
Bug fixes - executor.py running(): add capture_output=True to subprocess.run so pg_ctl status output no longer leaks to the terminal on every call; previously the change from getstatusoutput() dropped the implicit capture. - test_windows_compatibility.py: remove the module-level pytestmark that skipped every test on non-Windows. All tests in the file use patch() to mock platform.system() and subprocess calls, so none of them require a real Windows host; the blanket skip was silently hiding the entire template and process-management test suite from Linux/macOS CI runs. The unused sys import is removed along with the mark. Inline comment fixes - oldest-postgres.yml: narrow the 'install libpq' step condition to also require runner.os == 'Linux' so 'sudo apt install' is not attempted on non-Linux runners when the matrix entry contains PyPy. - executor.py Windows start() branch: build merged_env from os.environ.copy() updated with self.envvars so system-level PATH and other vital variables are inherited rather than replaced by the locale-only dict. - executor.py Windows start() branch: pass posix=False to shlex.split(self.startparams) so Windows backslashes in startparams are treated as literals rather than POSIX escape characters. Nitpick - newsfragments/1182.feature.rst: rewrite as a concise user-facing summary without internal symbol names. Made-with: Cursor
1 parent cc7fe02 commit d530337

4 files changed

Lines changed: 7 additions & 10 deletions

File tree

.github/workflows/oldest-postgres.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
run: |
5353
sudo locale-gen de_DE.UTF-8
5454
- name: install libpq
55-
if: ${{ contains(matrix.python-version, 'pypy') }}
55+
if: ${{ contains(matrix.python-version, 'pypy') && runner.os == 'Linux' }}
5656
run: sudo apt install libpq5
5757
- name: Install oldest supported versions
5858
uses: fizyk/actions-reuse/.github/actions/pipenv-run@v4.4.4

newsfragments/1182.feature.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Add Windows compatibility for ``PostgreSQLExecutor`` with platform-specific command templates (``UNIX_PROC_START_COMMAND`` / ``WINDOWS_PROC_START_COMMAND``) and a dedicated ``_windows_terminate_process`` method for graceful process termination on Windows.
1+
Add Windows support for ``PostgreSQLExecutor``, including platform-specific start/stop handling.

pytest_postgresql/executor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,12 @@ def start(self: T) -> T:
197197
pg_options,
198198
"-l",
199199
self.logfile,
200-
*shlex.split(self.startparams),
200+
*shlex.split(self.startparams, posix=False),
201201
]
202+
merged_env = os.environ.copy()
203+
merged_env.update(self.envvars)
202204
try:
203-
result = subprocess.run(args, check=False, env=self.envvars, timeout=self._timeout)
205+
result = subprocess.run(args, check=False, env=merged_env, timeout=self._timeout)
204206
except subprocess.TimeoutExpired as exc:
205207
# subprocess.run already killed the stuck pg_ctl process before
206208
# re-raising, so no additional cleanup is required here.
@@ -282,6 +284,7 @@ def running(self) -> bool:
282284
result = subprocess.run(
283285
[self.executable, "status", "-D", self.datadir],
284286
check=False,
287+
capture_output=True,
285288
)
286289
return result.returncode == 0
287290

tests/test_windows_compatibility.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22

33
import os
44
import subprocess
5-
import sys
65
from unittest.mock import MagicMock, patch
76

87
import pytest
98

109
from pytest_postgresql.executor import PostgreSQLExecutor
1110

12-
pytestmark = pytest.mark.skipif(
13-
sys.platform != "win32",
14-
reason="Windows-only tests",
15-
)
16-
1711

1812
class TestCommandTemplates:
1913
"""Test platform-specific command templates."""

0 commit comments

Comments
 (0)