Windows support
What action do you want to perform
Hi, we are wanting to use the postgresql_proc fixture in our test suite and we ran into a few errors. Version 2.4.0 on Windows 10 and PostgreSQL version 11.
What are the results
On the creation of PostgreSQLExecutor we find it errors when calling pg_ctl due to the quotes around stderr on this line , seems Windows is not happy. By removing the quotes it managed to set up the database and run the test suite.
However it now runs into the problem of not being able to stop with os.killpg, as this function doesn't exist for Windows.
@pytest.fixture(scope='session')
def postgresql_proc_fixture(request, tmpdir_factory):
"""
Process fixture for PostgreSQL.
:param FixtureRequest request: fixture request object
:rtype: pytest_dbfixtures.executors.TCPExecutor
:returns: tcp executor
"""
.
.
.
# start server
with postgresql_executor:
postgresql_executor.wait_for_postgres()
> yield postgresql_executor
..\..\appdata\local\pypoetry\cache\virtualenvs\trase-iwsqw52c-py3.7\lib\site-packages\pytest_postgresql\factories.py:200:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\..\appdata\local\pypoetry\cache\virtualenvs\trase-iwsqw52c-py3.7\lib\site-packages\mirakuru\base.py:179: in __exit__
self.stop()
..\..\appdata\local\pypoetry\cache\virtualenvs\trase-iwsqw52c-py3.7\lib\site-packages\pytest_postgresql\executor.py:220: in stop
super().stop(sig, exp_sig)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pytest_postgresql.executor.PostgreSQLExecutor: "C:/PROGRA~..." 0x194068a34a8>, sig = <Signals.SIGTERM: 15>, exp_sig = None
def stop(
self: SimpleExecutorType,
sig: int = None,
exp_sig: int = None
) -> SimpleExecutorType:
.
.
.
try:
> os.killpg(self.process.pid, sig)
E AttributeError: module 'os' has no attribute 'killpg'
What are the expected results
We were wondering if others have run into this issue too and if there's a way to get this fix in. Any help is appreciated as its a great plugin to use!
@pernlofgren I see there two issues, one is related to pytest-postgresql, the other to mirakuru ( https://github.com/ClearcodeHQ/mirakuru/issues/392 ).
In both cases, I have no resources (time and material) to develop and maintain windows solutions by myself. And to accept both solutions I'd need to have CI that runs tests against windows. I'd be happy to accept help in both cases though.
Thanks for the reply @fizyk. Unfortunately we are in the same boat with not enough resources at the moment. We have switched to using postgresql_noproc for our Windows users and this is working as expected. Will let you do what you want with this issue 😅
Should be easier to handle since pytest-postgresql CI got moved to github actions. Now it's a matter of adding a workflow for windows and fix issues there
As a quick fix until the issue is resolved, you could add the following to your conftest.py:
# fix the postgres command being executed, remove '' from stderr as they are passed literally and postgres won't start
PostgreSQLExecutor.BASE_PROC_START_COMMAND = PostgreSQLExecutor.BASE_PROC_START_COMMAND.replace("'stderr'", "stderr")
# windows process management is different, you cannot use killpg; use kill instead
import os
import signal
def killpg_windows(__pgid: int, __signal: int) -> None:
os.kill(__pgid, signal.CTRL_C_EVENT)
os.killpg = killpg_windows #type: ignore
Tried the above fix but didn't work on Github Actions:
# Start the process
try:
> hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
# no special security
None, None,
int(not close_fds),
creationflags,
env,
cwd,
startupinfo)
E FileNotFoundError: [WinError 2] The system cannot find the file specified
c:\hostedtoolcache\windows\python\3.8.10\x64\lib\subprocess.py:1311: FileNotFoundError