RobertCraigie / RobertCraigie/pyright-python

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

Open
#261 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
Python
Stars
277
Forks
31
Avg merge
4h 22m
Merged PRs (30d)
3

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/test_main.py::test_nodeenv and reproduce the RPM-style build, install, and pytest run described in the issue, including the network-disabled environment. Inspect the pyright CLI invocation and the reported Node module failure; done means the test passes during the isolated installed-package test cycle.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.