Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows support #303

Open
pernlofgren opened this issue Jul 16, 2020 · 5 comments
Open

Windows support #303

pernlofgren opened this issue Jul 16, 2020 · 5 comments

Comments

@pernlofgren
Copy link

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!

@fizyk
Copy link
Member

fizyk commented Jul 17, 2020

@pernlofgren I see there two issues, one is related to pytest-postgresql, the other to mirakuru ( ClearcodeHQ/mirakuru#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.

@pernlofgren
Copy link
Author

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 😅

@fizyk
Copy link
Member

fizyk commented May 4, 2021

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

@mathiasburger
Copy link

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

@fizyk fizyk pinned this issue Jul 4, 2022
@fizyk fizyk changed the title postgresql_proc on Windows 10 Windows support Jul 4, 2022
@amin-nejad
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants