pytest_postgresql example does not find file
NickName:pretend I have a cool name Ask DateTime:2022-03-07T17:23:49

pytest_postgresql example does not find file

I am currently trying to get pytest_postgresql running in my enviroment.

so I copyed the Sample test out of github readme:

def test_example_postgres(postgresql):
    """Check main postgresql fixture."""
    cur = postgresql.cursor()
    cur.execute("CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar);")
    postgresql.commit()
    cur.close()

I had an import error at first but thanks to the advice her: pytest_postgresql example raises import error psycopg I installed psycopg[binary] and it worked.

after than I tryed: pytest

I got:


(venv) C:\Users\a05922\PycharmProjects\try_out_pytest_postgresql>pytest
========================================================================================================== test session starts ===========================================================================================================
platform win32 -- Python 3.9.4, pytest-7.0.1, pluggy-1.0.0
rootdir: C:\Users\a05922\PycharmProjects\try_out_pytest_postgresql
plugins: postgresql-4.1.0
collected 1 item                                                                                                                                                                                                                          

test_postgresql.py E                                                                                                                                                                                                                [100%]

================================================================================================================= ERRORS =================================================================================================================
________________________________________________________________________________________________ ERROR at setup of test_example_postgres _________________________________________________________________________________________________

request = <SubRequest 'postgresql' for <Function test_example_postgres>>

    @pytest.fixture
    def postgresql_factory(request: FixtureRequest) -> Iterator[connection]:
        """
        Fixture factory for PostgreSQL.

        :param request: fixture request object
        :returns: postgresql client
        """
        check_for_psycopg()
>       proc_fixture: Union[PostgreSQLExecutor, NoopExecutor] = request.getfixturevalue(
            process_fixture_name
        )

venv\lib\site-packages\pytest_postgresql\factories\client.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv\lib\site-packages\pytest_postgresql\factories\process.py:104: in postgresql_proc_fixture
    pg_bindir = subprocess.check_output(
C:\Programme\Python\Python39\lib\subprocess.py:424: in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
C:\Programme\Python\Python39\lib\subprocess.py:505: in run
    with Popen(*popenargs, **kwargs) as process:
C:\Programme\Python\Python39\lib\subprocess.py:951: in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <Popen: returncode: None args: ['pg_config', '--bindir']>, args = 'pg_config --bindir', executable = None, preexec_fn = None, close_fds = False, pass_fds = (), cwd = None, env = None
startupinfo = <subprocess.STARTUPINFO object at 0x0000024768E90760>, creationflags = 0, shell = False, p2cread = Handle(636), p2cwrite = -1, c2pread = 14, c2pwrite = Handle(652), errread = -1, errwrite = Handle(648)
unused_restore_signals = True, unused_gid = None, unused_gids = None, unused_uid = None, unused_umask = -1, unused_start_new_session = False

    def _execute_child(self, args, executable, preexec_fn, close_fds,
                       pass_fds, cwd, env,
                       startupinfo, creationflags, shell,
                       p2cread, p2cwrite,
                       c2pread, c2pwrite,
                       errread, errwrite,
                       unused_restore_signals,
                       unused_gid, unused_gids, unused_uid,
                       unused_umask,
                       unused_start_new_session):
        """Execute program (MS Windows version)"""

        assert not pass_fds, "pass_fds not supported on Windows."

        if isinstance(args, str):
            pass
        elif isinstance(args, bytes):
            if shell:
                raise TypeError('bytes args is not allowed on Windows')
            args = list2cmdline([args])
        elif isinstance(args, os.PathLike):
            if shell:
                raise TypeError('path-like args is not allowed when '
                                'shell is true')
            args = list2cmdline([args])
        else:
            args = list2cmdline(args)

        if executable is not None:
            executable = os.fsdecode(executable)

        # Process startup details
        if startupinfo is None:
            startupinfo = STARTUPINFO()
        else:
            # bpo-34044: Copy STARTUPINFO since it is modified above,
            # so the caller can reuse it multiple times.
            startupinfo = startupinfo.copy()

        use_std_handles = -1 not in (p2cread, c2pwrite, errwrite)
        if use_std_handles:
            startupinfo.dwFlags |= _winapi.STARTF_USESTDHANDLES
            startupinfo.hStdInput = p2cread
            startupinfo.hStdOutput = c2pwrite
            startupinfo.hStdError = errwrite

        attribute_list = startupinfo.lpAttributeList
        have_handle_list = bool(attribute_list and
                                "handle_list" in attribute_list and
                                attribute_list["handle_list"])

        # If we were given an handle_list or need to create one
        if have_handle_list or (use_std_handles and close_fds):
            if attribute_list is None:
                attribute_list = startupinfo.lpAttributeList = {}
            handle_list = attribute_list["handle_list"] = \
                list(attribute_list.get("handle_list", []))

            if use_std_handles:
                handle_list += [int(p2cread), int(c2pwrite), int(errwrite)]

            handle_list[:] = self._filter_handle_list(handle_list)

            if handle_list:
                if not close_fds:
                    warnings.warn("startupinfo.lpAttributeList['handle_list'] "
                                  "overriding close_fds", RuntimeWarning)

                # When using the handle_list we always request to inherit
                # handles but the only handles that will be inherited are
                # the ones in the handle_list
                close_fds = False

        if shell:
            startupinfo.dwFlags |= _winapi.STARTF_USESHOWWINDOW
            startupinfo.wShowWindow = _winapi.SW_HIDE
            comspec = os.environ.get("COMSPEC", "cmd.exe")
            args = '{} /c "{}"'.format (comspec, args)

        if cwd is not None:
            cwd = os.fsdecode(cwd)

        sys.audit("subprocess.Popen", executable, args, cwd, env)

        # 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] Das System kann die angegebene Datei nicht finden

C:\Programme\Python\Python39\lib\subprocess.py:1420: FileNotFoundError
======================================================================================================== short test summary info =========================================================================================================
ERROR test_postgresql.py::test_example_postgres - FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden
============================================================================================================ 1 error in 0.36s ============================================================================================================

(venv) C:\Users\a05922\PycharmProjects\try_out_pytest_postgresql>

The German line at the end says: "The System can not finde the stated file"

I have a hard time figering this out. the argument that looks the most like a file name to me is cwd. that argument is created a few lines above from fsdecode as long as cwd already exists.

is the line:


self = <Popen: returncode: None args: ['pg_config', '--bindir']>, args = 'pg_config --bindir', executable = None, preexec_fn = None, close_fds = False, pass_fds = (), cwd = None, env = None
startupinfo = <subprocess.STARTUPINFO object at 0x0000024768E90760>, creationflags = 0, shell = False, p2cread = Handle(636), p2cwrite = -1, c2pread = 14, c2pwrite = Handle(652), errread = -1, errwrite = Handle(648)
unused_restore_signals = True, unused_gid = None, unused_gids = None, unused_uid = None, unused_umask = -1, unused_start_new_session = False

the arguments _execute_child is called with? if so cwd would be None and could not be the problem. Anyone any ideas?

Copyright Notice:Content Author:「pretend I have a cool name」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/71378841/pytest-postgresql-example-does-not-find-file

More about “pytest_postgresql example does not find file” related questions

pytest_postgresql example does not find file

I am currently trying to get pytest_postgresql running in my enviroment. so I copyed the Sample test out of github readme: def test_example_postgres(postgresql): &quot;&quot;&quot;Check main

Show Detail

pytest_postgresql example raises import error psycopg

I am currently trying to get pytest_postgresql running in my enviroment. befor I start: I can test the sql code it self with this right? not just things like your database connection would work lik...

Show Detail

pytest_postgresql example raises import error psycopg

I am currently trying to get pytest_postgresql running in my enviroment. befor I start: I can test the sql code it self with this right? not just things like your database connection would work lik...

Show Detail

Where can I find the example applicationContext.xml file

With Spring 3 distribution there was a project folder which was packaged in the distribution . This project folder had sample applicationContext.xml file which can be used . However when I have

Show Detail

File upload example for grapevine

I am new to Web API and REST services and looking to build a simple REST server which accepts file uploads. I found out grapevine which is simple and easy to understand. I couldn't find any file up...

Show Detail

How does import find the file path in Kotlin?

I've read the Kotlin doc (https://kotlinlang.org/docs/packages.html), and I understood that, when importing a package, the package name does not need to match the folder's path that stores the pack...

Show Detail

How does find-by-example work in the Pharo Finder?

One of the things I was most impressed with when digging into Pharo was that the Finder could do find-by-example. I'd previously only seen this in languages like Haskell, where it's possible to kno...

Show Detail

Find file that does not contain specific string

I want to find file that does not contain the specific string? The listed file is like below ../../../experiment/fileA.txt (contain word 'Book') ../../../experiment/fileB.txt (contain word 'Book')...

Show Detail

TensorFlow Android example: Cannot find WORKSPACE file

I installed TensorFlow on Ubuntu. I also installed Android NDK and SDK, in order to build the example application. According to the instructions, I now need to edit the WORKSPACE file to set the ND...

Show Detail

Javadoc warning - bad source file: file does not contain class com.example.MyClass

I have a file called MyFile.java and it contains multiple classes(none of them is public). Note that the file does not contain MyFile class. Apparently Javadoc is not happy about this and it genera...

Show Detail