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

1.1.357: pytest fails in tests/test_main.py::test_nodeenv unit in js code #261

Open
kloczek opened this issue Apr 10, 2024 · 2 comments
Open

Comments

@kloczek
Copy link

kloczek commented Apr 10, 2024

I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

  • python3 -sBm build -w --no-isolation
  • because I'm calling build with --no-isolation I'm using during all processes only locally installed modules
  • install .whl file in </install/prefix> using installer module
  • run pytest with $PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>
  • build is performed in env which is cut off from access to the public network (pytest is executed with -m "not network")
Here is pytest output:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pyright-1.1.357-2.fc37.x86_64/usr/lib64/python3.10/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pyright-1.1.357-2.fc37.x86_64/usr/lib/python3.10/site-packages
+ /usr/bin/pytest -ra -m 'not network'
============================= test session starts ==============================
platform linux -- Python 3.10.14, pytest-8.1.1, pluggy-1.4.0
rootdir: /home/tkloczko/rpmbuild/BUILD/pyright-python-1.1.357
configfile: pyproject.toml
plugins: subprocess-1.5.0
collected 28 items

tests/test_langserver.py ..                                              [  7%]
tests/test_main.py .............F..                                      [ 64%]
tests/test_node.py .........                                             [ 96%]
tests/test_types.py .                                                    [100%]

=================================== FAILURES ===================================
_________________________________ test_nodeenv _________________________________

    def test_nodeenv() -> None:
        """Ensure nodeenv is successfully downloaded and used"""
>       subprocess.run(
            [sys.executable, '-m', 'pyright', '--version'],
            check=True,
            stdout=subprocess.PIPE,
            env=dict(
                os.environ,
                PYRIGHT_PYTHON_GLOBAL_NODE='0',
            ),
        )

tests/test_main.py:194:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

input = None, capture_output = False, timeout = None, check = True
popenargs = (['/usr/bin/python3', '-m', 'pyright', '--version'],)
kwargs = {'env': {'AR': '/usr/bin/gcc-ar', 'ASMFLAGS': '-m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protecti...-Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -Wall -Werror=format-security', ...}, 'stdout': -1}
process = <Popen: returncode: 1 args: ['/usr/bin/python3', '-m', 'pyright', '--version']>
stdout = b'', stderr = None, retcode = 1

    def run(*popenargs,
            input=None, capture_output=False, timeout=None, check=False, **kwargs):
        """Run command with arguments and return a CompletedProcess instance.

        The returned instance will have attributes args, returncode, stdout and
        stderr. By default, stdout and stderr are not captured, and those attributes
        will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them,
        or pass capture_output=True to capture both.

        If check is True and the exit code was non-zero, it raises a
        CalledProcessError. The CalledProcessError object will have the return code
        in the returncode attribute, and output & stderr attributes if those streams
        were captured.

        If timeout is given, and the process takes too long, a TimeoutExpired
        exception will be raised.

        There is an optional argument "input", allowing you to
        pass bytes or a string to the subprocess's stdin.  If you use this argument
        you may not also use the Popen constructor's "stdin" argument, as
        it will be used internally.

        By default, all communication is in bytes, and therefore any "input" should
        be bytes, and the stdout and stderr will be bytes. If in text mode, any
        "input" should be a string, and stdout and stderr will be strings decoded
        according to locale encoding, or by "encoding" if set. Text mode is
        triggered by setting any of text, encoding, errors or universal_newlines.

        The other arguments are the same as for the Popen constructor.
        """
        if input is not None:
            if kwargs.get('stdin') is not None:
                raise ValueError('stdin and input arguments may not both be used.')
            kwargs['stdin'] = PIPE

        if capture_output:
            if kwargs.get('stdout') is not None or kwargs.get('stderr') is not None:
                raise ValueError('stdout and stderr arguments may not be used '
                                 'with capture_output.')
            kwargs['stdout'] = PIPE
            kwargs['stderr'] = PIPE

        with Popen(*popenargs, **kwargs) as process:
            try:
                stdout, stderr = process.communicate(input, timeout=timeout)
            except TimeoutExpired as exc:
                process.kill()
                if _mswindows:
                    # Windows accumulates the output in a single blocking
                    # read() call run on child threads, with the timeout
                    # being done in a join() on those threads.  communicate()
                    # _after_ kill() is required to collect that and add it
                    # to the exception.
                    exc.stdout, exc.stderr = process.communicate()
                else:
                    # POSIX _communicate already populated the output so
                    # far into the TimeoutExpired exception.
                    process.wait()
                raise
            except:  # Including KeyboardInterrupt, communicate handled that.
                process.kill()
                # We don't call process.wait() as .__exit__ does that for us.
                raise
            retcode = process.poll()
            if check and retcode:
>               raise CalledProcessError(retcode, process.args,
                                         output=stdout, stderr=stderr)
E               subprocess.CalledProcessError: Command '['/usr/bin/python3', '-m', 'pyright', '--version']' returned non-zero exit status 1.

/usr/lib64/python3.10/subprocess.py:526: CalledProcessError
----------------------------- Captured stderr call -----------------------------
internal/modules/cjs/loader.js:895
    throw err;
    ^

Error: Cannot find module 'node:util'
Require stack:
- /home/tkloczko/.cache/pyright-python/1.1.357/node_modules/pyright/dist/pyright.js
- /home/tkloczko/.cache/pyright-python/1.1.357/node_modules/pyright/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:892:15)
    at Function.Module._load (internal/modules/cjs/loader.js:785:27)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.9632 (/home/tkloczko/.cache/pyright-python/1.1.357/node_modules/pyright/dist/pyright.js:1:610)
    at o (/home/tkloczko/.cache/pyright-python/1.1.357/node_modules/pyright/dist/pyright.js:1:1243)
    at Object.1264 (/home/tkloczko/.cache/pyright-python/1.1.357/node_modules/pyright/dist/vendor.js:2:768634)
    at o (/home/tkloczko/.cache/pyright-python/1.1.357/node_modules/pyright/dist/pyright.js:1:1243)
    at Object.6476 (/home/tkloczko/.cache/pyright-python/1.1.357/node_modules/pyright/dist/pyright-internal.js:1:1101958)
    at o (/home/tkloczko/.cache/pyright-python/1.1.357/node_modules/pyright/dist/pyright.js:1:1243) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/tkloczko/.cache/pyright-python/1.1.357/node_modules/pyright/dist/pyright.js',
    '/home/tkloczko/.cache/pyright-python/1.1.357/node_modules/pyright/index.js'
  ]
}
=========================== short test summary info ============================
FAILED tests/test_main.py::test_nodeenv - subprocess.CalledProcessError: Comm...
======================== 1 failed, 27 passed in 24.23s =========================

Please let me know if you need more details or want me to perform some diagnostics.

@RobertCraigie
Copy link
Owner

RobertCraigie commented Apr 10, 2024

Thanks for the report. This is actually because you're using node.js v12 which is unfortunately not supported in the most recent versions of pyright. If you upgrade to a newer node version these tests should pass.

@RobertCraigie RobertCraigie closed this as not planned Won't fix, can't repro, duplicate, stale Apr 10, 2024
@kloczek
Copy link
Author

kloczek commented Apr 10, 2024

Nope, I'm using nodejs 20.12.1.

@RobertCraigie RobertCraigie reopened this Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants