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

0.18.2: pytest is failing in one unit #1896

Closed
kloczek opened this issue Nov 26, 2022 · 18 comments
Closed

0.18.2: pytest is failing in one unit #1896

kloczek opened this issue Nov 26, 2022 · 18 comments

Comments

@kloczek
Copy link

kloczek commented Nov 26, 2022

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>
  • run pytest with PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>

Here is pytest output:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-jedi-0.18.2-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-jedi-0.18.2-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.15, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/jedi-0.18.2, configfile: pytest.ini, testpaths: jedi, test
collected 3863 items

jedi/__init__.py .                                                                                                                                                   [  0%]
jedi/api/__init__.py .                                                                                                                                               [  0%]
jedi/api/classes.py .....                                                                                                                                            [  0%]
jedi/api/replstartup.py .                                                                                                                                            [  0%]
jedi/inference/context.py .                                                                                                                                          [  0%]
jedi/inference/docstrings.py ..                                                                                                                                      [  0%]
jedi/inference/sys_path.py .                                                                                                                                         [  0%]
test/conftest.py .                                                                                                                                                   [  0%]
test/test_cache.py ..                                                                                                                                                [  0%]
test/test_debug.py .                                                                                                                                                 [  0%]
test/test_file_io.py ..                                                                                                                                              [  0%]
test/test_integration.py ........................................................................................................................................... [  4%]
.................................................................................................................................................................... [  8%]
.................................................................................................................................................................... [ 12%]
................................................................ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss.............. [ 16%]
.................................................................................................................................................................... [ 21%]
.................................................................................................................................................................... [ 25%]
.................................................................................................................................................................... [ 29%]
.................................................................................................................................................................... [ 33%]
.................................................................................................................................................................... [ 38%]
.................................................................................................................................................................... [ 42%]
.................................................................................................................................................................... [ 46%]
.................................................................................................................................................................... [ 50%]
...................................................^Z
[1]+  Stopped                 rpmbuild -ba --with check --with failing_tests python-jedi.spec

[tkloczko@pers-jacek SPECS]$ fg
rpmbuild -ba --with check --with failing_tests python-jedi.spec
................................................................................................................. [ 55%]
.................................................................................................................................................................... [ 59%]
................................                                                                                                                                     [ 60%]
test/test_settings.py ...                                                                                                                                            [ 60%]
test/test_utils.py ..........                                                                                                                                        [ 60%]
test/test_api/test_analysis.py .                                                                                                                                     [ 60%]
test/test_api/test_api.py ..................................................                                                                                         [ 61%]
test/test_api/test_api_classes_follow_definition.py ....                                                                                                             [ 61%]
test/test_api/test_call_signatures.py .............................................................................................................................. [ 65%]
...............................................................................                                                                                      [ 67%]
test/test_api/test_classes.py ............................................                                                                                           [ 68%]
test/test_api/test_documentation.py ..                                                                                                                               [ 68%]
test/test_api/test_classes.py ......                                                                                                                                 [ 68%]
test/test_api/test_documentation.py ..                                                                                                                               [ 68%]
test/test_api/test_classes.py ......                                                                                                                                 [ 68%]
test/test_api/test_documentation.py ..                                                                                                                               [ 68%]
test/test_api/test_classes.py .........................................................                                                                              [ 70%]
test/test_api/test_completion.py ................................................................................................................................... [ 73%]
............                                                                                                                                                         [ 73%]
test/test_api/test_context.py .........................................                                                                                              [ 74%]
test/test_api/test_documentation.py .................................                                                                                                [ 75%]
test/test_api/test_environment.py ..ss.s..............                                                                                                               [ 76%]
test/test_api/test_full_name.py .............                                                                                                                        [ 76%]
test/test_api/test_interpreter.py .................................................................................................................................. [ 80%]
...                                                                                                                                                                  [ 80%]
test/test_api/test_keyword.py ....                                                                                                                                   [ 80%]
test/test_api/test_names.py ........................                                                                                                                 [ 80%]
test/test_api/test_project.py .........................................................                                                                              [ 82%]
test/test_api/test_refactoring.py ....                                                                                                                               [ 82%]
test/test_api/test_search.py ............................                                                                                                            [ 83%]
test/test_api/test_settings.py .                                                                                                                                     [ 83%]
test/test_api/test_signatures.py ...................                                                                                                                 [ 83%]
test/test_api/test_syntax_errors.py .........                                                                                                                        [ 83%]
test/test_api/test_unicode.py ......                                                                                                                                 [ 84%]
test/test_api/test_usages.py ............                                                                                                                            [ 84%]
test/test_inference/test_annotations.py .......                                                                                                                      [ 84%]
test/test_inference/test_buildout_detection.py ......                                                                                                                [ 84%]
test/test_inference/test_compiled.py ...........................                                                                                                     [ 85%]
test/test_inference/test_context.py ..                                                                                                                               [ 85%]
test/test_inference/test_docstring.py .............sssssssssssss..................                                                                                   [ 86%]
test/test_inference/test_extension.py .....                                                                                                                          [ 86%]
test/test_inference/test_fstring.py .                                                                                                                                [ 86%]
test/test_inference/test_implicit_namespace_package.py ......                                                                                                        [ 86%]
test/test_inference/test_imports.py ..........................xxxx...........................................                                                        [ 88%]
test/test_inference/test_literals.py ...                                                                                                                             [ 88%]
test/test_inference/test_mixed.py .................                                                                                                                  [ 89%]
test/test_inference/test_namespace_package.py ................                                                                                                       [ 89%]
test/test_inference/test_precedence.py ..x                                                                                                                           [ 89%]
test/test_inference/test_pyc.py ..                                                                                                                                   [ 89%]
test/test_inference/test_representation.py ..                                                                                                                        [ 89%]
test/test_inference/test_signature.py ..................................................................................................                             [ 92%]
test/test_inference/test_stdlib.py .......                                                                                                                           [ 92%]
test/test_inference/test_sys_path.py .F................ss.....                                                                                                       [ 93%]
test/test_inference/test_gradual/test_conversion.py ......                                                                                                           [ 93%]
test/test_inference/test_gradual/test_stub_loading.py ...........................                                                                                    [ 94%]
test/test_inference/test_gradual/test_stubs.py ..................................................................................................................... [ 97%]
...............................................................                                                                                                      [ 98%]
test/test_inference/test_gradual/test_typeshed.py ............................                                                                                       [ 99%]
test/test_parso_integration/test_basic.py ......                                                                                                                     [ 99%]
test/test_parso_integration/test_error_correction.py ....                                                                                                            [ 99%]
test/test_parso_integration/test_parser_utils.py ........                                                                                                            [100%]

================================================================================= FAILURES =================================================================================
____________________________________________________________________________ test_venv_and_pths ____________________________________________________________________________

venv_path = '/tmp/pytest-of-tkloczko/pytest-1481/venv_path0/venv'

    def test_venv_and_pths(venv_path):
        pjoin = os.path.join

        site_pkg_path = pjoin(venv_path, 'lib')
        if os.name == 'nt':
            site_pkg_path = pjoin(site_pkg_path, 'site-packages')
        else:
            site_pkg_path = glob(pjoin(site_pkg_path, 'python*', 'site-packages'))[0]
        shutil.rmtree(site_pkg_path)
        shutil.copytree(get_example_dir('sample_venvs', 'pth_directory'), site_pkg_path)

        virtualenv = create_environment(venv_path)
        venv_paths = virtualenv.get_sys_path()

        ETALON = [
            # For now disable egg-links. I have no idea how they work... ~ dave
            #pjoin('/path', 'from', 'egg-link'),
            #pjoin(site_pkg_path, '.', 'relative', 'egg-link', 'path'),
            site_pkg_path,
            pjoin(site_pkg_path, 'dir-from-foo-pth'),
            '/foo/smth.py:module',
            # Not sure why it's added twice. It has to do with site.py which is not
            # something we can change. However this obviously also doesn't matter.
            '/foo/smth.py:from_func',
            '/foo/smth.py:from_func',
        ]

        # Ensure that pth and egg-link paths were added.
>       assert venv_paths[-len(ETALON):] == ETALON
E       AssertionError: assert ['/tmp/pytest...py:from_func'] == ['/tmp/pytest...py:from_func']
E         At index 2 diff: '/foo/smth.py:from_func' != '/foo/smth.py:module'
E         Use -v to get more diff

test/test_inference/test_sys_path.py:61: AssertionError
========================================================================= short test summary info ==========================================================================
SKIPPED [86] test/test_integration.py:45: Needs django to be installed to run this test.
SKIPPED [3] test/test_api/test_environment.py:38: Skipped
SKIPPED [1] test/test_inference/test_docstring.py:176: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:193: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:209: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:228: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:246: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:261: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:283: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:304: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:326: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:347: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:368: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:390: numpydoc or numpy module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:402: numpydoc or numpy module is unavailable
SKIPPED [2] test/test_inference/test_sys_path.py:70: condition: sys.platform!='win32'
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.foo; flask.ext.foo.-Foo]
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.bar; flask.ext.bar.-Foo]
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.baz; flask.ext.baz.-Foo]
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.moo; flask.ext.moo.-Foo]
XFAIL test/test_inference/test_precedence.py::test_equals[... == ...]
FAILED test/test_inference/test_sys_path.py::test_venv_and_pths - AssertionError: assert ['/tmp/pytest...py:from_func'] == ['/tmp/pytest...py:from_func']
==================================================== 1 failed, 3753 passed, 104 skipped, 5 xfailed in 145.10s (0:02:25) ====================================================

Here is list of installed modules in build env

Package                       Version
----------------------------- -----------------
alabaster                     0.7.12
appdirs                       1.4.4
attrs                         22.1.0
Babel                         2.11.0
Brlapi                        0.8.3
build                         0.9.0
charset-normalizer            3.0.1
colorama                      0.4.6
contourpy                     1.0.6
cssselect                     1.1.0
cycler                        0.11.0
distro                        1.8.0
dnspython                     2.2.1
docopt                        0.6.2
docutils                      0.19
exceptiongroup                1.0.0
extras                        1.0.0
fixtures                      4.0.0
fonttools                     4.38.0
gpg                           1.17.1-unknown
idna                          3.4
imagesize                     1.4.1
importlib-metadata            5.1.0
iniconfig                     1.1.1
Jinja2                        3.1.2
kiwisolver                    1.4.4
libcomps                      0.1.19
louis                         3.23.0
lxml                          4.9.1
MarkupSafe                    2.1.1
matplotlib                    3.6.2
numpy                         1.23.1
olefile                       0.46
packaging                     21.3
parso                         0.8.3
path                          16.5.0
pbr                           5.9.0
pep517                        0.13.0
Pillow                        9.3.0
pip                           22.3.1
pluggy                        1.0.0
Pygments                      2.13.0
PyGObject                     3.42.2
pyparsing                     3.0.9
pytest                        7.2.0
python-dateutil               2.8.2
pytz                          2022.4
requests                      2.28.1
rpm                           4.17.0
scour                         0.38.2
setuptools                    65.6.3
six                           1.16.0
snowballstemmer               2.2.0
Sphinx                        5.3.0
sphinx-rtd-theme              1.1.1
sphinxcontrib-applehelp       1.0.2.dev20220730
sphinxcontrib-devhelp         1.0.2.dev20220730
sphinxcontrib-htmlhelp        2.0.0
sphinxcontrib-jsmath          1.0.1.dev20220730
sphinxcontrib-qthelp          1.0.3.dev20220730
sphinxcontrib-serializinghtml 1.1.5
testtools                     2.5.0
tomli                         2.0.1
urllib3                       1.26.12
wheel                         0.38.4
zipp                          3.11.0
@davidhalter
Copy link
Owner

No idea why this happens, but I feel like you could probably also skip this test. Feel free to PR this if you realize what's wrong. I won't be able to reproduce this I guess.

@kloczek
Copy link
Author

kloczek commented Nov 26, 2022

I;ve added for now that unit to --deselect list.
Are you able to reporosuce that issue? 🤔

@davidhalter
Copy link
Owner

I'm not trying to reproduce it, because I feel like this is such a rare problem, that you have to debug it yourself.

@kloczek
Copy link
Author

kloczek commented Jun 28, 2023

Updated output after update build env

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-jedi-0.18.2-5.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-jedi-0.18.2-5.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra -m 'not network'
============================= test session starts ==============================
platform linux -- Python 3.8.17, pytest-7.4.0, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/jedi-0.18.2
configfile: pytest.ini
testpaths: jedi, test
collected 3863 items

jedi/__init__.py .                                                       [  0%]
jedi/api/__init__.py .                                                   [  0%]
jedi/api/classes.py .....                                                [  0%]
jedi/api/replstartup.py .                                                [  0%]
jedi/inference/context.py .                                              [  0%]
jedi/inference/docstrings.py ..                                          [  0%]
jedi/inference/sys_path.py .                                             [  0%]
test/conftest.py .                                                       [  0%]
test/test_cache.py ..                                                    [  0%]
test/test_debug.py .                                                     [  0%]
test/test_file_io.py ..                                                  [  0%]
test/test_integration.py ............................................... [  1%]
........................................................................ [  3%]
........................................................................ [  5%]
........................................................................ [  7%]
........................................................................ [  9%]
........................................................................ [ 11%]
........................................................................ [ 12%]
....................................................ssssssssssssssssssss [ 14%]
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...... [ 16%]
........................................................................ [ 18%]
........................................................................ [ 20%]
........................................................................ [ 22%]
........................................................................ [ 24%]
........................................................................ [ 25%]
........................................................................ [ 27%]
........................................................................ [ 29%]
........................................................................ [ 31%]
........................................................................ [ 33%]
........................................................................ [ 35%]
........................................................................ [ 37%]
........................................................................ [ 38%]
........................................................................ [ 40%]
........................................................................ [ 42%]
........................................................................ [ 44%]
........................................................................ [ 46%]
........................................................................ [ 48%]
........................................................................ [ 50%]
........................................................................ [ 52%]
........................................................................ [ 53%]
........................................................................ [ 55%]
........................................................................ [ 57%]
........................................................................ [ 59%]
........................                                                 [ 60%]
test/test_settings.py ...                                                [ 60%]
test/test_utils.py ..........                                            [ 60%]
test/test_api/test_analysis.py .                                         [ 60%]
test/test_api/test_api.py .............................................. [ 61%]
....                                                                     [ 61%]
test/test_api/test_api_classes_follow_definition.py ....                 [ 61%]
test/test_api/test_call_signatures.py .................................. [ 62%]
........................................................................ [ 64%]
........................................................................ [ 66%]
...........................                                              [ 67%]
test/test_api/test_classes.py .......................................... [ 68%]
..                                                                       [ 68%]
test/test_api/test_documentation.py ..                                   [ 68%]
test/test_api/test_classes.py ......                                     [ 68%]
test/test_api/test_documentation.py ..                                   [ 68%]
test/test_api/test_classes.py ......                                     [ 68%]
test/test_api/test_documentation.py ..                                   [ 68%]
test/test_api/test_classes.py .......................................... [ 69%]
...............                                                          [ 70%]
test/test_api/test_completion.py ....................................... [ 71%]
........................................................................ [ 73%]
................................                                         [ 73%]
test/test_api/test_context.py .........................................  [ 74%]
test/test_api/test_documentation.py .................................    [ 75%]
test/test_api/test_environment.py ..ss.s.....EEE.....E                   [ 76%]
test/test_api/test_full_name.py .............                            [ 76%]
test/test_api/test_interpreter.py ...................................... [ 77%]
........................................................................ [ 79%]
.......................                                                  [ 80%]
test/test_api/test_keyword.py ....                                       [ 80%]
test/test_api/test_names.py ........................                     [ 80%]
test/test_api/test_project.py .......................................... [ 81%]
...............                                                          [ 82%]
test/test_api/test_refactoring.py ....                                   [ 82%]
test/test_api/test_search.py ............................                [ 83%]
test/test_api/test_settings.py .                                         [ 83%]
test/test_api/test_signatures.py ...................                     [ 83%]
test/test_api/test_syntax_errors.py .........                            [ 83%]
test/test_api/test_unicode.py ......                                     [ 84%]
test/test_api/test_usages.py ............                                [ 84%]
test/test_inference/test_annotations.py .......                          [ 84%]
test/test_inference/test_buildout_detection.py ......                    [ 84%]
test/test_inference/test_compiled.py ...........................         [ 85%]
test/test_inference/test_context.py ..                                   [ 85%]
test/test_inference/test_docstring.py .............sssssssssssss........ [ 86%]
..........                                                               [ 86%]
test/test_inference/test_extension.py .....                              [ 86%]
test/test_inference/test_fstring.py .                                    [ 86%]
test/test_inference/test_implicit_namespace_package.py ......            [ 86%]
test/test_inference/test_imports.py ..........................xxxx...... [ 87%]
.....................................                                    [ 88%]
test/test_inference/test_literals.py ...                                 [ 88%]
test/test_inference/test_mixed.py .................                      [ 89%]
test/test_inference/test_namespace_package.py ................           [ 89%]
test/test_inference/test_precedence.py ..x                               [ 89%]
test/test_inference/test_pyc.py ..                                       [ 89%]
test/test_inference/test_representation.py ..                            [ 89%]
test/test_inference/test_signature.py .................................. [ 90%]
....................................................sssss.......         [ 92%]
test/test_inference/test_stdlib.py .......                               [ 92%]
test/test_inference/test_sys_path.py .E................ss.....           [ 93%]
test/test_inference/test_gradual/test_conversion.py ......               [ 93%]
test/test_inference/test_gradual/test_stub_loading.py .................. [ 93%]
.........                                                                [ 94%]
test/test_inference/test_gradual/test_stubs.py ......................... [ 94%]
........................................................................ [ 96%]
........................................................................ [ 98%]
...........                                                              [ 98%]
test/test_inference/test_gradual/test_typeshed.py ...................... [ 99%]
......                                                                   [ 99%]
test/test_parso_integration/test_basic.py ......                         [ 99%]
test/test_parso_integration/test_error_correction.py ....                [ 99%]
test/test_parso_integration/test_parser_utils.py ........                [100%]

==================================== ERRORS ====================================
_____________________ ERROR at setup of test_working_venv ______________________

tmpdir_factory = TempdirFactory(_tmppath_factory=TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7f3c8a0dae20>, _basetemp=PosixPath('/tmp/pytest-of-tkloczko/pytest-47'), _retention_count=3, _retention_policy='all'))
environment = <Environment: 3.8.17 in /usr>

    @pytest.fixture(scope='session')
    def venv_path(tmpdir_factory, environment):
        if isinstance(environment, InterpreterEnvironment):
            # The environment can be a tox virtualenv environment which we don't
            # want, so use the system environment.
            environment = get_system_environment(
                '.'.join(str(x) for x in environment.version_info[:2])
            )

        tmpdir = tmpdir_factory.mktemp('venv_path')
        dirname = os.path.join(tmpdir.strpath, 'venv')

        # We cannot use the Python from tox because tox creates virtualenvs and
        # they have different site.py files that work differently than the default
        # ones. Instead, we find the real Python executable by printing the value
        # of sys.base_prefix or sys.real_prefix if we are in a virtualenv.
        output = subprocess.check_output([
            environment.executable, "-c",
            "import sys; "
            "print(sys.real_prefix if hasattr(sys, 'real_prefix') else sys.base_prefix)"
        ])
        prefix = output.rstrip().decode('utf8')
        if os.name == 'nt':
            executable_path = os.path.join(prefix, 'python')
        else:
            executable_name = os.path.basename(environment.executable)
            executable_path = os.path.join(prefix, 'bin', executable_name)

        return_code = subprocess.call([executable_path, '-m', 'venv', dirname])
>       assert return_code == 0, return_code
E       AssertionError: 1
E       assert 1 == 0

test/conftest.py:128: AssertionError
---------------------------- Captured stderr setup -----------------------------
Error: Command '['/tmp/pytest-of-tkloczko/pytest-47/venv_path0/venv/bin/python3.8', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
____________________ ERROR at setup of test_scanning_venvs _____________________

tmpdir_factory = TempdirFactory(_tmppath_factory=TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7f3c8a0dae20>, _basetemp=PosixPath('/tmp/pytest-of-tkloczko/pytest-47'), _retention_count=3, _retention_policy='all'))
environment = <Environment: 3.8.17 in /usr>

    @pytest.fixture(scope='session')
    def venv_path(tmpdir_factory, environment):
        if isinstance(environment, InterpreterEnvironment):
            # The environment can be a tox virtualenv environment which we don't
            # want, so use the system environment.
            environment = get_system_environment(
                '.'.join(str(x) for x in environment.version_info[:2])
            )

        tmpdir = tmpdir_factory.mktemp('venv_path')
        dirname = os.path.join(tmpdir.strpath, 'venv')

        # We cannot use the Python from tox because tox creates virtualenvs and
        # they have different site.py files that work differently than the default
        # ones. Instead, we find the real Python executable by printing the value
        # of sys.base_prefix or sys.real_prefix if we are in a virtualenv.
        output = subprocess.check_output([
            environment.executable, "-c",
            "import sys; "
            "print(sys.real_prefix if hasattr(sys, 'real_prefix') else sys.base_prefix)"
        ])
        prefix = output.rstrip().decode('utf8')
        if os.name == 'nt':
            executable_path = os.path.join(prefix, 'python')
        else:
            executable_name = os.path.basename(environment.executable)
            executable_path = os.path.join(prefix, 'bin', executable_name)

        return_code = subprocess.call([executable_path, '-m', 'venv', dirname])
>       assert return_code == 0, return_code
E       AssertionError: 1
E       assert 1 == 0

test/conftest.py:128: AssertionError
_____________ ERROR at setup of test_create_environment_venv_path ______________

tmpdir_factory = TempdirFactory(_tmppath_factory=TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7f3c8a0dae20>, _basetemp=PosixPath('/tmp/pytest-of-tkloczko/pytest-47'), _retention_count=3, _retention_policy='all'))
environment = <Environment: 3.8.17 in /usr>

    @pytest.fixture(scope='session')
    def venv_path(tmpdir_factory, environment):
        if isinstance(environment, InterpreterEnvironment):
            # The environment can be a tox virtualenv environment which we don't
            # want, so use the system environment.
            environment = get_system_environment(
                '.'.join(str(x) for x in environment.version_info[:2])
            )

        tmpdir = tmpdir_factory.mktemp('venv_path')
        dirname = os.path.join(tmpdir.strpath, 'venv')

        # We cannot use the Python from tox because tox creates virtualenvs and
        # they have different site.py files that work differently than the default
        # ones. Instead, we find the real Python executable by printing the value
        # of sys.base_prefix or sys.real_prefix if we are in a virtualenv.
        output = subprocess.check_output([
            environment.executable, "-c",
            "import sys; "
            "print(sys.real_prefix if hasattr(sys, 'real_prefix') else sys.base_prefix)"
        ])
        prefix = output.rstrip().decode('utf8')
        if os.name == 'nt':
            executable_path = os.path.join(prefix, 'python')
        else:
            executable_name = os.path.basename(environment.executable)
            executable_path = os.path.join(prefix, 'bin', executable_name)

        return_code = subprocess.call([executable_path, '-m', 'venv', dirname])
>       assert return_code == 0, return_code
E       AssertionError: 1
E       assert 1 == 0

test/conftest.py:128: AssertionError
_____________________ ERROR at setup of test_changing_venv _____________________

tmpdir_factory = TempdirFactory(_tmppath_factory=TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7f3c8a0dae20>, _basetemp=PosixPath('/tmp/pytest-of-tkloczko/pytest-47'), _retention_count=3, _retention_policy='all'))
environment = <Environment: 3.8.17 in /usr>

    @pytest.fixture(scope='session')
    def venv_path(tmpdir_factory, environment):
        if isinstance(environment, InterpreterEnvironment):
            # The environment can be a tox virtualenv environment which we don't
            # want, so use the system environment.
            environment = get_system_environment(
                '.'.join(str(x) for x in environment.version_info[:2])
            )

        tmpdir = tmpdir_factory.mktemp('venv_path')
        dirname = os.path.join(tmpdir.strpath, 'venv')

        # We cannot use the Python from tox because tox creates virtualenvs and
        # they have different site.py files that work differently than the default
        # ones. Instead, we find the real Python executable by printing the value
        # of sys.base_prefix or sys.real_prefix if we are in a virtualenv.
        output = subprocess.check_output([
            environment.executable, "-c",
            "import sys; "
            "print(sys.real_prefix if hasattr(sys, 'real_prefix') else sys.base_prefix)"
        ])
        prefix = output.rstrip().decode('utf8')
        if os.name == 'nt':
            executable_path = os.path.join(prefix, 'python')
        else:
            executable_name = os.path.basename(environment.executable)
            executable_path = os.path.join(prefix, 'bin', executable_name)

        return_code = subprocess.call([executable_path, '-m', 'venv', dirname])
>       assert return_code == 0, return_code
E       AssertionError: 1
E       assert 1 == 0

test/conftest.py:128: AssertionError
_____________________ ERROR at setup of test_venv_and_pths _____________________

tmpdir_factory = TempdirFactory(_tmppath_factory=TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7f3c8a0dae20>, _basetemp=PosixPath('/tmp/pytest-of-tkloczko/pytest-47'), _retention_count=3, _retention_policy='all'))
environment = <Environment: 3.8.17 in /usr>

    @pytest.fixture(scope='session')
    def venv_path(tmpdir_factory, environment):
        if isinstance(environment, InterpreterEnvironment):
            # The environment can be a tox virtualenv environment which we don't
            # want, so use the system environment.
            environment = get_system_environment(
                '.'.join(str(x) for x in environment.version_info[:2])
            )

        tmpdir = tmpdir_factory.mktemp('venv_path')
        dirname = os.path.join(tmpdir.strpath, 'venv')

        # We cannot use the Python from tox because tox creates virtualenvs and
        # they have different site.py files that work differently than the default
        # ones. Instead, we find the real Python executable by printing the value
        # of sys.base_prefix or sys.real_prefix if we are in a virtualenv.
        output = subprocess.check_output([
            environment.executable, "-c",
            "import sys; "
            "print(sys.real_prefix if hasattr(sys, 'real_prefix') else sys.base_prefix)"
        ])
        prefix = output.rstrip().decode('utf8')
        if os.name == 'nt':
            executable_path = os.path.join(prefix, 'python')
        else:
            executable_name = os.path.basename(environment.executable)
            executable_path = os.path.join(prefix, 'bin', executable_name)

        return_code = subprocess.call([executable_path, '-m', 'venv', dirname])
>       assert return_code == 0, return_code
E       AssertionError: 1
E       assert 1 == 0

test/conftest.py:128: AssertionError
=============================== warnings summary ===============================
test/test_integration.py::test_completion[conftest:27]
  /home/tkloczko/rpmbuild/BUILD/jedi-0.18.2/jedi/plugins/pytest.py:140: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
    from pkg_resources import iter_entry_points

test/test_integration.py::test_completion[conftest:27]
test/test_integration.py::test_completion[conftest:27]
test/test_integration.py::test_completion[conftest:27]
test/test_integration.py::test_completion[conftest:27]
test/test_integration.py::test_completion[conftest:27]
  /usr/lib/python3.8/site-packages/pkg_resources/__init__.py:2871: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('sphinxcontrib')`.
  Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    declare_namespace(pkg)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
SKIPPED [86] test/test_integration.py:45: Needs django to be installed to run this test.
SKIPPED [3] test/test_api/test_environment.py:38: Skipped
SKIPPED [1] test/test_inference/test_docstring.py:176: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:193: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:209: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:228: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:246: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:261: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:283: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:304: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:326: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:347: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:368: numpydoc module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:390: numpydoc or numpy module is unavailable
SKIPPED [1] test/test_inference/test_docstring.py:402: numpydoc or numpy module is unavailable
SKIPPED [5] test/test_inference/test_signature.py:380: attrs needed in target environment to run this test
SKIPPED [2] test/test_inference/test_sys_path.py:70: condition: sys.platform!='win32'
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.foo; flask.ext.foo.-Foo]
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.bar; flask.ext.bar.-Foo]
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.baz; flask.ext.baz.-Foo]
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.moo; flask.ext.moo.-Foo]
XFAIL test/test_inference/test_precedence.py::test_equals[... == ...]
ERROR test/test_api/test_environment.py::test_working_venv - AssertionError: 1
ERROR test/test_api/test_environment.py::test_scanning_venvs - AssertionError: 1
ERROR test/test_api/test_environment.py::test_create_environment_venv_path - ...
ERROR test/test_api/test_environment.py::test_changing_venv - AssertionError: 1
ERROR test/test_inference/test_sys_path.py::test_venv_and_pths - AssertionErr...
= 3744 passed, 109 skipped, 5 xfailed, 6 warnings, 5 errors in 90.44s (0:01:30) =

Found issue:

  • use deprecated pkg_resources module
  • use python -m <foo> - pytest and venv should not be used like that because when python executes python -m <foo> it adds by default current path to sys.path

@kloczek
Copy link
Author

kloczek commented Jul 7, 2023

I found that test/test_api/test_environment.py units have been ailing with error because I had installed locally .whl archoives of pip and setuptools.
After that I found still those units have been failing because it is hardcoded python executable name.
Here is proposition of the fix for that issue

--- a/test/conftest.py
+++ b/test/conftest.py
@@ -118,13 +118,8 @@
         "print(sys.real_prefix if hasattr(sys, 'real_prefix') else sys.base_prefix)"
     ])
     prefix = output.rstrip().decode('utf8')
-    if os.name == 'nt':
-        executable_path = os.path.join(prefix, 'python')
-    else:
-        executable_name = os.path.basename(environment.executable)
-        executable_path = os.path.join(prefix, 'bin', executable_name)

-    return_code = subprocess.call([executable_path, '-m', 'venv', dirname])
+    return_code = subprocess.call([sys.executable, '-m', 'venv', dirname])
     assert return_code == 0, return_code
     return dirname

Please let me know if you want this as PR.

Still needs to be fixed issue with use deprecated pkg_resources module.

@kloczek
Copy link
Author

kloczek commented Jul 7, 2023

Still I have one unit failing

========================================================================================= FAILURES ==========================================================================================
____________________________________________________________________________________ test_venv_and_pths _____________________________________________________________________________________

venv_path = '/tmp/pytest-of-tkloczko/pytest-32/venv_path0/venv'

    def test_venv_and_pths(venv_path):
        pjoin = os.path.join

        site_pkg_path = pjoin(venv_path, 'lib')
        if os.name == 'nt':
            site_pkg_path = pjoin(site_pkg_path, 'site-packages')
        else:
            site_pkg_path = glob(pjoin(site_pkg_path, 'python*', 'site-packages'))[0]
        shutil.rmtree(site_pkg_path)
        shutil.copytree(get_example_dir('sample_venvs', 'pth_directory'), site_pkg_path)

        virtualenv = create_environment(venv_path)
        venv_paths = virtualenv.get_sys_path()

        ETALON = [
            # For now disable egg-links. I have no idea how they work... ~ dave
            #pjoin('/path', 'from', 'egg-link'),
            #pjoin(site_pkg_path, '.', 'relative', 'egg-link', 'path'),
            site_pkg_path,
            pjoin(site_pkg_path, 'dir-from-foo-pth'),
            '/foo/smth.py:module',
            # Not sure why it's added twice. It has to do with site.py which is not
            # something we can change. However this obviously also doesn't matter.
            '/foo/smth.py:from_func',
            '/foo/smth.py:from_func',
        ]

        # Ensure that pth and egg-link paths were added.
>       assert venv_paths[-len(ETALON):] == ETALON
E       AssertionError: assert ['/tmp/pytest...py:from_func'] == ['/tmp/pytest...py:from_func']
E         At index 2 diff: '/foo/smth.py:from_func' != '/foo/smth.py:module'
E         Use -v to get more diff

test/test_inference/test_sys_path.py:61: AssertionError
===================================================================================== warnings summary ======================================================================================
test/test_integration.py::test_completion[conftest:27]
  /home/tkloczko/rpmbuild/BUILD/jedi-0.18.2/jedi/plugins/pytest.py:140: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
    from pkg_resources import iter_entry_points

test/test_integration.py::test_completion[conftest:27]
test/test_integration.py::test_completion[conftest:27]
test/test_integration.py::test_completion[conftest:27]
test/test_integration.py::test_completion[conftest:27]
test/test_integration.py::test_completion[conftest:27]
  /usr/lib/python3.8/site-packages/pkg_resources/__init__.py:2871: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('sphinxcontrib')`.
  Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    declare_namespace(pkg)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================== short test summary info ==================================================================================
SKIPPED [86] test/test_integration.py:45: Needs django to be installed to run this test.
SKIPPED [3] test/test_api/test_environment.py:38: Skipped
SKIPPED [5] test/test_inference/test_signature.py:380: attrs needed in target environment to run this test
SKIPPED [2] test/test_inference/test_sys_path.py:70: condition: sys.platform!='win32'
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.foo; flask.ext.foo.-Foo]
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.bar; flask.ext.bar.-Foo]
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.baz; flask.ext.baz.-Foo]
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.moo; flask.ext.moo.-Foo]
XFAIL test/test_inference/test_precedence.py::test_equals[... == ...]
FAILED test/test_inference/test_sys_path.py::test_venv_and_pths - AssertionError: assert ['/tmp/pytest...py:from_func'] == ['/tmp/pytest...py:from_func']
======================================================= 1 failed, 3761 passed, 96 skipped, 5 xfailed, 6 warnings in 99.41s (0:01:39) ========================================================
/usr/lib/python3.8/site-packages/_pytest/pathlib.py:95: PytestWarning: (rm_rf) error removing /tmp/pytest-of-tkloczko/garbage-653ff4bc-9549-451f-905c-5eaa6497e007/test_rmtree_errorhandler_rerai0
<class 'OSError'>: [Errno 39] Directory not empty: 'test_rmtree_errorhandler_rerai0'
  warnings.warn(
/usr/lib/python3.8/site-packages/_pytest/pathlib.py:95: PytestWarning: (rm_rf) error removing /tmp/pytest-of-tkloczko/garbage-653ff4bc-9549-451f-905c-5eaa6497e007/test_rmtree_errorhandler_reado0
<class 'OSError'>: [Errno 39] Directory not empty: 'test_rmtree_errorhandler_reado0'
  warnings.warn(
/usr/lib/python3.8/site-packages/_pytest/pathlib.py:95: PytestWarning: (rm_rf) error removing /tmp/pytest-of-tkloczko/garbage-653ff4bc-9549-451f-905c-5eaa6497e007/test_safe_delete_no_perms0
<class 'OSError'>: [Errno 39] Directory not empty: 'test_safe_delete_no_perms0'
  warnings.warn(
/usr/lib/python3.8/site-packages/_pytest/pathlib.py:95: PytestWarning: (rm_rf) error removing /tmp/pytest-of-tkloczko/garbage-653ff4bc-9549-451f-905c-5eaa6497e007/test_safe_set_no_perms0
<class 'OSError'>: [Errno 39] Directory not empty: 'test_safe_set_no_perms0'
  warnings.warn(
/usr/lib/python3.8/site-packages/_pytest/pathlib.py:95: PytestWarning: (rm_rf) error removing /tmp/pytest-of-tkloczko/garbage-653ff4bc-9549-451f-905c-5eaa6497e007/test_safe_get_no_perms0
<class 'OSError'>: [Errno 39] Directory not empty: 'test_safe_get_no_perms0'
  warnings.warn(
/usr/lib/python3.8/site-packages/_pytest/pathlib.py:95: PytestWarning: (rm_rf) error removing /tmp/pytest-of-tkloczko/garbage-653ff4bc-9549-451f-905c-5eaa6497e007
<class 'OSError'>: [Errno 39] Directory not empty: '/tmp/pytest-of-tkloczko/garbage-653ff4bc-9549-451f-905c-5eaa6497e007'
  warnings.warn(

@kloczek
Copy link
Author

kloczek commented Jul 7, 2023

I'm not sure but in this case instead using special procedure for nt it shoudl be used directly what provides:

[tkloczko@pers-jacek SPECS]$ python3 -Ic "import sysconfig; print(sysconfig.get_path('platlib'))"
/usr/lib64/python3.8/site-packages
[tkloczko@pers-jacek SPECS]$ python3 -Ic "import sysconfig; print(sysconfig.get_path('purelib'))"
/usr/lib/python3.8/site-packages

@davidhalter
Copy link
Owner

Sorry, but I don't understand at all what you're referring to.

@kloczek
Copy link
Author

kloczek commented Jul 7, 2023

I\m talking about code fragment which pytest dumped is in fail log

   def test_venv_and_pths(venv_path):
        pjoin = os.path.join

        site_pkg_path = pjoin(venv_path, 'lib')
        if os.name == 'nt':
            site_pkg_path = pjoin(site_pkg_path, 'site-packages')
        else:
            site_pkg_path = glob(pjoin(site_pkg_path, 'python*', 'site-packages'))[0]
        shutil.rmtree(site_pkg_path)
        shutil.copytree(get_example_dir('sample_venvs', 'pth_directory'), site_pkg_path)

        virtualenv = create_environment(venv_path)
        venv_paths = virtualenv.get_sys_path()

@davidhalter
Copy link
Owner

I still have no idea what you mean.

@kloczek
Copy link
Author

kloczek commented Jul 7, 2023

In quoted fragment of the code are assembled paths which could be taken directly from sysconfig.

@davidhalter
Copy link
Owner

If that helps, I guess that's fine. Feel free to send a pull request and I will check if CI passes (and if it works on my machine).

@kloczek
Copy link
Author

kloczek commented Mar 25, 2024

I just tested 0.19.1 and looks like now most of the units are failing because it is hardcoded python interpreter name as python3.9.
In such cases it should be used rather sys.executable.

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-jedi-0.19.1-4.fc36.x86_64/usr/lib64/python3.9/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-jedi-0.19.1-4.fc36.x86_64/usr/lib/python3.9/site-packages
+ /usr/bin/pytest -ra -m 'not network' --deselect test/test_inference/test_sys_path.py::test_venv_and_pths
============================= test session starts ==============================
platform linux -- Python 3.9.18, pytest-8.1.1, pluggy-1.4.0
rootdir: /home/tkloczko/rpmbuild/BUILD/jedi-0.19.1
configfile: pytest.ini
testpaths: jedi, test
collected 3886 items / 1 deselected / 3885 selected

jedi/__init__.py .                                                       [  0%]
jedi/api/__init__.py .                                                   [  0%]
jedi/api/classes.py .....                                                [  0%]
jedi/api/replstartup.py .                                                [  0%]
jedi/inference/context.py .                                              [  0%]
jedi/inference/docstrings.py ..                                          [  0%]
jedi/inference/sys_path.py .                                             [  0%]
test/conftest.py .                                                       [  0%]
test/test_api/test_analysis.py E                                         [  0%]
test/test_api/test_api.py .EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [  1%]
EEEE                                                                     [  1%]
test/test_api/test_api_classes_follow_definition.py EEEE                 [  1%]
test/test_api/test_call_signatures.py EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [  2%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [  4%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [  6%]
EEEEEEEEEEEEEEEEEEEEEEEEEEE                                              [  7%]
test/test_api/test_classes.py EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [  8%]
EE                                                                       [  8%]
test/test_api/test_documentation.py EE                                   [  8%]
test/test_api/test_classes.py EEEEEE                                     [  8%]
test/test_api/test_documentation.py EE                                   [  8%]
test/test_api/test_classes.py EEEEEE                                     [  8%]
test/test_api/test_documentation.py EE                                   [  8%]
test/test_api/test_classes.py EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [  9%]
EEEEEEEEEEEEEEE                                                          [ 10%]
test/test_api/test_completion.py EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 11%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 12%]
EEEEEEEEEEEEEEEEEEEEEEEEE..EEEEE                                         [ 13%]
test/test_api/test_context.py EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE  [ 14%]
test/test_api/test_documentation.py EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE   [ 15%]
test/test_api/test_environment.py .FssssEEEE.EEE.....E                   [ 16%]
test/test_api/test_full_name.py EEEEEEEEEEEEE                            [ 16%]
test/test_api/test_interpreter.py ...................................... [ 17%]
........................................................................ [ 19%]
..........................................                               [ 20%]
test/test_api/test_keyword.py EEEE                                       [ 20%]
test/test_api/test_names.py EEEEEEEEEEEEEEEEEEEEEEEE                     [ 21%]
test/test_api/test_project.py EE.E...................................... [ 22%]
........EEEE...                                                          [ 22%]
test/test_api/test_refactoring.py EEEEE                                  [ 22%]
test/test_api/test_search.py EEEEEEEEEEEEEEEEEEEEEEEEEEEE                [ 23%]
test/test_api/test_settings.py E                                         [ 23%]
test/test_api/test_signatures.py EEEEEEEEEEEEEEEEEEE                     [ 24%]
test/test_api/test_syntax_errors.py EEEEEEEEE                            [ 24%]
test/test_api/test_unicode.py EEEEEE                                     [ 24%]
test/test_api/test_usages.py EEEEEEEEEEEE                                [ 24%]
test/test_cache.py EE                                                    [ 24%]
test/test_debug.py .                                                     [ 24%]
test/test_file_io.py ..                                                  [ 24%]
test/test_inference/test_annotations.py EEEEEEE                          [ 25%]
test/test_inference/test_buildout_detection.py EEEEEE                    [ 25%]
test/test_inference/test_compiled.py EEE.EEEEEEEEEEEEEEEEEEEEEEE         [ 25%]
test/test_inference/test_context.py EE                                   [ 25%]
test/test_inference/test_docstring.py EEEEEEEEEEEEE.............EEEEEEEE [ 26%]
EEEEEEEEEE                                                               [ 27%]
test/test_inference/test_extension.py EEEss                              [ 27%]
test/test_inference/test_fstring.py E                                    [ 27%]
test/test_inference/test_gradual/test_conversion.py EEEEEE               [ 27%]
test/test_inference/test_gradual/test_stub_loading.py EEEEEEEEEEEEEEEEEE [ 27%]
EEEEEEEEE                                                                [ 28%]
test/test_inference/test_gradual/test_stubs.py EEEEEEEEEEEEEEEEEEEEEEEEE [ 28%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 30%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 32%]
EEEEEEEEEEE                                                              [ 32%]
test/test_inference/test_gradual/test_typeshed.py ..EEEEEEEEEEEEEEEEEEEE [ 33%]
EEEEEE                                                                   [ 33%]
test/test_inference/test_implicit_namespace_package.py EEEEEE            [ 33%]
test/test_inference/test_imports.py ...EEEEEEEEEEEEEEEEEEEEEEExxxxEEEEEE [ 34%]
EEEEEEEEEEEEEEEEE..........EEEEEEEEEE                                    [ 35%]
test/test_inference/test_literals.py EEE                                 [ 35%]
test/test_inference/test_mixed.py .................                      [ 35%]
test/test_inference/test_namespace_package.py EEEEEEEEEEEEEEEE           [ 36%]
test/test_inference/test_precedence.py EEx                               [ 36%]
test/test_inference/test_pyc.py EE                                       [ 36%]
test/test_inference/test_representation.py EE                            [ 36%]
test/test_inference/test_signature.py EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 37%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE           [ 39%]
test/test_inference/test_stdlib.py EEEEEEE                               [ 39%]
test/test_inference/test_sys_path.py E................ss.....            [ 39%]
test/test_integration.py EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 41%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 42%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 44%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 46%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 48%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 50%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 52%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 54%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 55%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 57%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 59%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 61%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 63%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 65%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 66%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 68%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 70%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 72%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 74%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 76%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 78%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 79%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 81%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 83%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 85%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 87%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 89%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 91%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 92%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 94%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 96%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 98%]
EEEEEEEEEEEEEEEEEEEEEEEEEEEE                                             [ 99%]
test/test_parso_integration/test_basic.py EEEEEE                         [ 99%]
test/test_parso_integration/test_error_correction.py EEEE                [ 99%]
test/test_parso_integration/test_parser_utils.py .......E                [ 99%]
test/test_settings.py EEE                                                [ 99%]
test/test_utils.py ..........                                            [100%]

==================================== ERRORS ====================================
_______________________ ERROR at setup of test_issue436 ________________________

request = <SubRequest 'environment' for <Function test_issue436>>

    @pytest.fixture(scope='session')
    def environment(request):
        version = request.config.option.env
        if version is None:
            v = str(sys.version_info[0]) + str(sys.version_info[1])
            version = os.environ.get('JEDI_TEST_ENVIRONMENT', v)

        if request.config.option.interpreter_env or version == 'interpreter':
            return InterpreterEnvironment()

        if '.' not in version:
            version = version[0] + '.' + version[1:]
>       return get_system_environment(version)

conftest.py:105:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

version = '3.9'

    def get_system_environment(version, *, env_vars=None):
        """
        Return the first Python environment found for a string of the form 'X.Y'
        where X and Y are the major and minor versions of Python.

        :raises: :exc:`.InvalidPythonEnvironment`
        :returns: :class:`.Environment`
        """
        exe = which('python' + version)
        if exe:
            if exe == sys.executable:
                return SameEnvironment()
            return Environment(exe)

        if os.name == 'nt':
            for exe in _get_executables_from_windows_registry(version):
                try:
                    return Environment(exe, env_vars=env_vars)
                except InvalidPythonEnvironment:
                    pass
>       raise InvalidPythonEnvironment("Cannot find executable python%s." % version)
E       jedi.api.environment.InvalidPythonEnvironment: Cannot find executable python3.9.

jedi/api/environment.py:353: InvalidPythonEnvironment
_____________________ ERROR at setup of test_empty_script ______________________

request = <SubRequest 'environment' for <Function test_issue436>>

    @pytest.fixture(scope='session')
    def environment(request):
        version = request.config.option.env
        if version is None:
            v = str(sys.version_info[0]) + str(sys.version_info[1])
            version = os.environ.get('JEDI_TEST_ENVIRONMENT', v)

        if request.config.option.interpreter_env or version == 'interpreter':
            return InterpreterEnvironment()

        if '.' not in version:
            version = version[0] + '.' + version[1:]
>       return get_system_environment(version)

conftest.py:105:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

version = '3.9'

    def get_system_environment(version, *, env_vars=None):
        """
        Return the first Python environment found for a string of the form 'X.Y'
        where X and Y are the major and minor versions of Python.

        :raises: :exc:`.InvalidPythonEnvironment`
        :returns: :class:`.Environment`
        """
        exe = which('python' + version)
        if exe:
            if exe == sys.executable:
                return SameEnvironment()
            return Environment(exe)

        if os.name == 'nt':
            for exe in _get_executables_from_windows_registry(version):
                try:
                    return Environment(exe, env_vars=env_vars)
                except InvalidPythonEnvironment:
                    pass
>       raise InvalidPythonEnvironment("Cannot find executable python%s." % version)
E       jedi.api.environment.InvalidPythonEnvironment: Cannot find executable python3.9.

jedi/api/environment.py:353: InvalidPythonEnvironment

Almost all units are failing the same way 🤔

@kloczek
Copy link
Author

kloczek commented Mar 25, 2024

With below patch:

--- a/test/conftest.py
+++ b/test/conftest.py
@@ -118,13 +118,8 @@
         "print(sys.real_prefix if hasattr(sys, 'real_prefix') else sys.base_prefix)"
     ])
     prefix = output.rstrip().decode('utf8')
-    if os.name == 'nt':
-        executable_path = os.path.join(prefix, 'python')
-    else:
-        executable_name = os.path.basename(environment.executable)
-        executable_path = os.path.join(prefix, 'bin', executable_name)

-    return_code = subprocess.call([executable_path, '-m', 'venv', dirname])
+    return_code = subprocess.call([sys.executable, '-m', 'venv', dirname])
     assert return_code == 0, return_code
     return dirname

--- a/jedi/api/environment.py
+++ b/jedi/api/environment.py
@@ -338,7 +338,7 @@
     :raises: :exc:`.InvalidPythonEnvironment`
     :returns: :class:`.Environment`
     """
-    exe = which('python' + version)
+    exe = sys.executable
     if exe:
         if exe == sys.executable:
             return SameEnvironment()

I was able to pass almost all units

Here is pytest output:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-jedi-0.19.1-4.fc36.x86_64/usr/lib64/python3.9/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-jedi-0.19.1-4.fc36.x86_64/usr/lib/python3.9/site-packages
+ /usr/bin/pytest -ra -m 'not network'
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.9.18, pytest-8.1.1, pluggy-1.4.0
rootdir: /home/tkloczko/rpmbuild/BUILD/jedi-0.19.1
configfile: pytest.ini
testpaths: jedi, test
plugins: asyncio-0.23.6, rerunfailures-12.0, anyio-4.3.0, hypothesis-6.99.11
asyncio: mode=strict
collected 3886 items

jedi/__init__.py .                                                                                                                                                                    [  0%]
jedi/api/__init__.py .                                                                                                                                                                [  0%]
jedi/api/classes.py .....                                                                                                                                                             [  0%]
jedi/api/replstartup.py .                                                                                                                                                             [  0%]
jedi/inference/context.py .                                                                                                                                                           [  0%]
jedi/inference/docstrings.py ..                                                                                                                                                       [  0%]
jedi/inference/sys_path.py .                                                                                                                                                          [  0%]
test/conftest.py .                                                                                                                                                                    [  0%]
test/test_api/test_analysis.py .                                                                                                                                                      [  0%]
test/test_api/test_api.py ..................................................                                                                                                          [  1%]
test/test_api/test_api_classes_follow_definition.py ....                                                                                                                              [  1%]
test/test_api/test_call_signatures.py ............................................................................................................................................... [  5%]
..............................................................                                                                                                                        [  7%]
test/test_api/test_classes.py ............................................                                                                                                            [  8%]
test/test_api/test_documentation.py ..                                                                                                                                                [  8%]
test/test_api/test_classes.py ......                                                                                                                                                  [  8%]
test/test_api/test_documentation.py ..                                                                                                                                                [  8%]
test/test_api/test_classes.py ......                                                                                                                                                  [  8%]
test/test_api/test_documentation.py ..                                                                                                                                                [  8%]
test/test_api/test_classes.py .........................................................                                                                                               [ 10%]
test/test_api/test_completion.py ...............................................................................................................................................      [ 13%]
test/test_api/test_context.py .........................................                                                                                                               [ 14%]
test/test_api/test_documentation.py ..................................                                                                                                                [ 15%]
test/test_api/test_environment.py ..FFF...............                                                                                                                                [ 16%]
test/test_api/test_full_name.py .............                                                                                                                                         [ 16%]
test/test_api/test_interpreter.py ................................................................................................................................................... [ 20%]
.....                                                                                                                                                                                 [ 20%]
test/test_api/test_keyword.py ....                                                                                                                                                    [ 20%]
test/test_api/test_names.py ........................                                                                                                                                  [ 21%]
test/test_api/test_project.py .........................................................                                                                                               [ 22%]
test/test_api/test_refactoring.py .....                                                                                                                                               [ 22%]
test/test_api/test_search.py ............................                                                                                                                             [ 23%]
test/test_api/test_settings.py .                                                                                                                                                      [ 23%]
test/test_api/test_signatures.py ...................                                                                                                                                  [ 24%]
test/test_api/test_syntax_errors.py .........                                                                                                                                         [ 24%]
test/test_api/test_unicode.py ......                                                                                                                                                  [ 24%]
test/test_api/test_usages.py ............                                                                                                                                             [ 24%]
test/test_cache.py ..                                                                                                                                                                 [ 24%]
test/test_debug.py .                                                                                                                                                                  [ 24%]
test/test_file_io.py ..                                                                                                                                                               [ 24%]
test/test_inference/test_annotations.py .......                                                                                                                                       [ 25%]
test/test_inference/test_buildout_detection.py ......                                                                                                                                 [ 25%]
test/test_inference/test_compiled.py ...........................                                                                                                                      [ 25%]
test/test_inference/test_context.py ..                                                                                                                                                [ 25%]
test/test_inference/test_docstring.py ............................................                                                                                                    [ 27%]
test/test_inference/test_extension.py ...ss                                                                                                                                           [ 27%]
test/test_inference/test_fstring.py .                                                                                                                                                 [ 27%]
test/test_inference/test_gradual/test_conversion.py ......                                                                                                                            [ 27%]
test/test_inference/test_gradual/test_stub_loading.py ...........................                                                                                                     [ 28%]
test/test_inference/test_gradual/test_stubs.py ...................................................................................................................................... [ 31%]
..............................................                                                                                                                                        [ 32%]
test/test_inference/test_gradual/test_typeshed.py ............................                                                                                                        [ 33%]
test/test_inference/test_implicit_namespace_package.py ......                                                                                                                         [ 33%]
test/test_inference/test_imports.py ..........................xxxx...........................................                                                                         [ 35%]
test/test_inference/test_literals.py ...                                                                                                                                              [ 35%]
test/test_inference/test_mixed.py .................                                                                                                                                   [ 35%]
test/test_inference/test_namespace_package.py ................                                                                                                                        [ 36%]
test/test_inference/test_precedence.py ..x                                                                                                                                            [ 36%]
test/test_inference/test_pyc.py ..                                                                                                                                                    [ 36%]
test/test_inference/test_representation.py ..                                                                                                                                         [ 36%]
test/test_inference/test_signature.py ................................................................................................                                                [ 39%]
test/test_inference/test_stdlib.py .......                                                                                                                                            [ 39%]
test/test_inference/test_sys_path.py .F................ss.....                                                                                                                        [ 39%]
test/test_integration.py ............................................................................................................................................................ [ 43%]
..................................................................................................................................................................................... [ 48%]
..................................................................................................................................................................................... [ 53%]
..............ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss................................................................................. [ 57%]
..................................................................................................................................................................................... [ 62%]
..................................................................................................................................................................................... [ 67%]
..................................................................................................................................................................................... [ 71%]
..................................................................................................................................................................................... [ 76%]
..................................................................................................................................................................................... [ 81%]
..................................................................................................................................................................................... [ 85%]
..................................................................................................................................................................................... [ 90%]
..................................................................................................................................................................................... [ 95%]
................................................................................................................................................................                      [ 99%]
test/test_parso_integration/test_basic.py ......                                                                                                                                      [ 99%]
test/test_parso_integration/test_error_correction.py ....                                                                                                                             [ 99%]
test/test_parso_integration/test_parser_utils.py ........                                                                                                                             [ 99%]
test/test_settings.py ...                                                                                                                                                             [ 99%]
test/test_utils.py ..........                                                                                                                                                         [100%]

========================================================================================= FAILURES ==========================================================================================
____________________________________________________________________________________ test_versions[3.6] _____________________________________________________________________________________

version = '3.6'

    @pytest.mark.parametrize(
        'version',
        ['3.6', '3.7', '3.8', '3.9']
    )
    def test_versions(version):
        try:
            env = get_system_environment(version)
        except InvalidPythonEnvironment:
            if int(version.replace('.', '')) == str(sys.version_info[0]) + str(sys.version_info[1]):
                # At least the current version has to work
                raise
            pytest.skip()

>       assert version == str(env.version_info[0]) + '.' + str(env.version_info[1])
E       AssertionError: assert '3.6' == '3.9'
E
E         - 3.9
E         + 3.6

test/test_api/test_environment.py:40: AssertionError
____________________________________________________________________________________ test_versions[3.7] _____________________________________________________________________________________

version = '3.7'

    @pytest.mark.parametrize(
        'version',
        ['3.6', '3.7', '3.8', '3.9']
    )
    def test_versions(version):
        try:
            env = get_system_environment(version)
        except InvalidPythonEnvironment:
            if int(version.replace('.', '')) == str(sys.version_info[0]) + str(sys.version_info[1]):
                # At least the current version has to work
                raise
            pytest.skip()

>       assert version == str(env.version_info[0]) + '.' + str(env.version_info[1])
E       AssertionError: assert '3.7' == '3.9'
E
E         - 3.9
E         + 3.7

test/test_api/test_environment.py:40: AssertionError
____________________________________________________________________________________ test_versions[3.8] _____________________________________________________________________________________

version = '3.8'

    @pytest.mark.parametrize(
        'version',
        ['3.6', '3.7', '3.8', '3.9']
    )
    def test_versions(version):
        try:
            env = get_system_environment(version)
        except InvalidPythonEnvironment:
            if int(version.replace('.', '')) == str(sys.version_info[0]) + str(sys.version_info[1]):
                # At least the current version has to work
                raise
            pytest.skip()

>       assert version == str(env.version_info[0]) + '.' + str(env.version_info[1])
E       AssertionError: assert '3.8' == '3.9'
E
E         - 3.9
E         + 3.8

test/test_api/test_environment.py:40: AssertionError
____________________________________________________________________________________ test_venv_and_pths _____________________________________________________________________________________

venv_path = '/tmp/pytest-of-tkloczko/pytest-125/venv_path0/venv', environment = <SameEnvironment: 3.9.18 in /usr>

    def test_venv_and_pths(venv_path, environment):
        pjoin = os.path.join

        if os.name == 'nt':
            if environment.version_info < (3, 11):
                site_pkg_path = pjoin(venv_path, 'lib', 'site-packages')
            else:
                site_pkg_path = pjoin(venv_path, 'Lib', 'site-packages')
        else:
            site_pkg_path = glob(pjoin(venv_path, 'lib', 'python*', 'site-packages'))[0]
        shutil.rmtree(site_pkg_path)
        shutil.copytree(get_example_dir('sample_venvs', 'pth_directory'), site_pkg_path)

        virtualenv = create_environment(venv_path)
        venv_paths = virtualenv.get_sys_path()

        ETALON = [
            # For now disable egg-links. I have no idea how they work... ~ dave
            #pjoin('/path', 'from', 'egg-link'),
            #pjoin(site_pkg_path, '.', 'relative', 'egg-link', 'path'),
            site_pkg_path,
            pjoin(site_pkg_path, 'dir-from-foo-pth'),
            '/foo/smth.py:module',
            # Not sure why it's added twice. It has to do with site.py which is not
            # something we can change. However this obviously also doesn't matter.
            '/foo/smth.py:from_func',
            '/foo/smth.py:from_func',
        ]

        # Ensure that pth and egg-link paths were added.
>       assert venv_paths[-len(ETALON):] == ETALON
E       AssertionError: assert ['/tmp/pytest...py:from_func'] == ['/tmp/pytest...py:from_func']
E
E         At index 2 diff: '/foo/smth.py:from_func' != '/foo/smth.py:module'
E         Use -v to get more diff

test/test_inference/test_sys_path.py:63: AssertionError
========================================================================================= XFAILURES =========================================================================================
_________________________________________________________________ test_flask_ext[import flask.ext.foo; flask.ext.foo.-Foo] __________________________________________________________________

Script = functools.partial(<class 'jedi.api.Script'>, environment=<SameEnvironment: 3.9.18 in /usr>), code = 'import flask.ext.foo; flask.ext.foo.', name = 'Foo'

    @pytest.mark.parametrize("code,name", [
        ("from flask.ext import foo; foo.", "Foo"),  # flask_foo.py
        ("from flask.ext import bar; bar.", "Bar"),  # flaskext/bar.py
        ("from flask.ext import baz; baz.", "Baz"),  # flask_baz/__init__.py
        ("from flask.ext import moo; moo.", "Moo"),  # flaskext/moo/__init__.py
        ("from flask.ext.", "foo"),
        ("from flask.ext.", "bar"),
        ("from flask.ext.", "baz"),
        ("from flask.ext.", "moo"),
        pytest.param("import flask.ext.foo; flask.ext.foo.", "Foo", marks=pytest.mark.xfail),
        pytest.param("import flask.ext.bar; flask.ext.bar.", "Foo", marks=pytest.mark.xfail),
        pytest.param("import flask.ext.baz; flask.ext.baz.", "Foo", marks=pytest.mark.xfail),
        pytest.param("import flask.ext.moo; flask.ext.moo.", "Foo", marks=pytest.mark.xfail),
    ])
    def test_flask_ext(Script, code, name):
        """flask.ext.foo is really imported from flaskext.foo or flask_foo.
        """
        path = get_example_dir('flask-site-packages')
        completions = Script(code, project=Project('.', sys_path=[path])).complete()
>       assert name in [c.name for c in completions]
E       AssertionError: assert 'Foo' in []

test/test_inference/test_imports.py:169: AssertionError
_________________________________________________________________ test_flask_ext[import flask.ext.bar; flask.ext.bar.-Foo] __________________________________________________________________

Script = functools.partial(<class 'jedi.api.Script'>, environment=<SameEnvironment: 3.9.18 in /usr>), code = 'import flask.ext.bar; flask.ext.bar.', name = 'Foo'

    @pytest.mark.parametrize("code,name", [
        ("from flask.ext import foo; foo.", "Foo"),  # flask_foo.py
        ("from flask.ext import bar; bar.", "Bar"),  # flaskext/bar.py
        ("from flask.ext import baz; baz.", "Baz"),  # flask_baz/__init__.py
        ("from flask.ext import moo; moo.", "Moo"),  # flaskext/moo/__init__.py
        ("from flask.ext.", "foo"),
        ("from flask.ext.", "bar"),
        ("from flask.ext.", "baz"),
        ("from flask.ext.", "moo"),
        pytest.param("import flask.ext.foo; flask.ext.foo.", "Foo", marks=pytest.mark.xfail),
        pytest.param("import flask.ext.bar; flask.ext.bar.", "Foo", marks=pytest.mark.xfail),
        pytest.param("import flask.ext.baz; flask.ext.baz.", "Foo", marks=pytest.mark.xfail),
        pytest.param("import flask.ext.moo; flask.ext.moo.", "Foo", marks=pytest.mark.xfail),
    ])
    def test_flask_ext(Script, code, name):
        """flask.ext.foo is really imported from flaskext.foo or flask_foo.
        """
        path = get_example_dir('flask-site-packages')
        completions = Script(code, project=Project('.', sys_path=[path])).complete()
>       assert name in [c.name for c in completions]
E       AssertionError: assert 'Foo' in []

test/test_inference/test_imports.py:169: AssertionError
_________________________________________________________________ test_flask_ext[import flask.ext.baz; flask.ext.baz.-Foo] __________________________________________________________________

Script = functools.partial(<class 'jedi.api.Script'>, environment=<SameEnvironment: 3.9.18 in /usr>), code = 'import flask.ext.baz; flask.ext.baz.', name = 'Foo'

    @pytest.mark.parametrize("code,name", [
        ("from flask.ext import foo; foo.", "Foo"),  # flask_foo.py
        ("from flask.ext import bar; bar.", "Bar"),  # flaskext/bar.py
        ("from flask.ext import baz; baz.", "Baz"),  # flask_baz/__init__.py
        ("from flask.ext import moo; moo.", "Moo"),  # flaskext/moo/__init__.py
        ("from flask.ext.", "foo"),
        ("from flask.ext.", "bar"),
        ("from flask.ext.", "baz"),
        ("from flask.ext.", "moo"),
        pytest.param("import flask.ext.foo; flask.ext.foo.", "Foo", marks=pytest.mark.xfail),
        pytest.param("import flask.ext.bar; flask.ext.bar.", "Foo", marks=pytest.mark.xfail),
        pytest.param("import flask.ext.baz; flask.ext.baz.", "Foo", marks=pytest.mark.xfail),
        pytest.param("import flask.ext.moo; flask.ext.moo.", "Foo", marks=pytest.mark.xfail),
    ])
    def test_flask_ext(Script, code, name):
        """flask.ext.foo is really imported from flaskext.foo or flask_foo.
        """
        path = get_example_dir('flask-site-packages')
        completions = Script(code, project=Project('.', sys_path=[path])).complete()
>       assert name in [c.name for c in completions]
E       AssertionError: assert 'Foo' in []

test/test_inference/test_imports.py:169: AssertionError
_________________________________________________________________ test_flask_ext[import flask.ext.moo; flask.ext.moo.-Foo] __________________________________________________________________

Script = functools.partial(<class 'jedi.api.Script'>, environment=<SameEnvironment: 3.9.18 in /usr>), code = 'import flask.ext.moo; flask.ext.moo.', name = 'Foo'

    @pytest.mark.parametrize("code,name", [
        ("from flask.ext import foo; foo.", "Foo"),  # flask_foo.py
        ("from flask.ext import bar; bar.", "Bar"),  # flaskext/bar.py
        ("from flask.ext import baz; baz.", "Baz"),  # flask_baz/__init__.py
        ("from flask.ext import moo; moo.", "Moo"),  # flaskext/moo/__init__.py
        ("from flask.ext.", "foo"),
        ("from flask.ext.", "bar"),
        ("from flask.ext.", "baz"),
        ("from flask.ext.", "moo"),
        pytest.param("import flask.ext.foo; flask.ext.foo.", "Foo", marks=pytest.mark.xfail),
        pytest.param("import flask.ext.bar; flask.ext.bar.", "Foo", marks=pytest.mark.xfail),
        pytest.param("import flask.ext.baz; flask.ext.baz.", "Foo", marks=pytest.mark.xfail),
        pytest.param("import flask.ext.moo; flask.ext.moo.", "Foo", marks=pytest.mark.xfail),
    ])
    def test_flask_ext(Script, code, name):
        """flask.ext.foo is really imported from flaskext.foo or flask_foo.
        """
        path = get_example_dir('flask-site-packages')
        completions = Script(code, project=Project('.', sys_path=[path])).complete()
>       assert name in [c.name for c in completions]
E       AssertionError: assert 'Foo' in []

test/test_inference/test_imports.py:169: AssertionError
__________________________________________________________________________________ test_equals[... == ...] __________________________________________________________________________________

Script = functools.partial(<class 'jedi.api.Script'>, environment=<SameEnvironment: 3.9.18 in /usr>), environment = <SameEnvironment: 3.9.18 in /usr>, source = '... == ...'

    @pytest.mark.parametrize('source', [
        pytest.param('1 == 1'),
        pytest.param('1.0 == 1'),
        # Unfortunately for now not possible, because it's a typeshed object.
        pytest.param('... == ...', marks=pytest.mark.xfail),
    ])
    def test_equals(Script, environment, source):
        script = Script(source)
        node = script._module_node.children[0]
>       first, = script._get_module_context().infer_node(node)
E       ValueError: too many values to unpack (expected 1)

test/test_inference/test_precedence.py:15: ValueError
================================================================================== short test summary info ==================================================================================
SKIPPED [2] test/test_inference/test_extension.py:35: condition: sys.platform != "linux" or sys.maxsize <= 2**32 or sys.version_info[:2] != (3, 8)
SKIPPED [2] test/test_inference/test_sys_path.py:72: condition: sys.platform!='win32'
SKIPPED [86] test/test_integration.py:46: Needs django to be installed to run this test.
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.foo; flask.ext.foo.-Foo]
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.bar; flask.ext.bar.-Foo]
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.baz; flask.ext.baz.-Foo]
XFAIL test/test_inference/test_imports.py::test_flask_ext[import flask.ext.moo; flask.ext.moo.-Foo]
XFAIL test/test_inference/test_precedence.py::test_equals[... == ...]
FAILED test/test_api/test_environment.py::test_versions[3.6] - AssertionError: assert '3.6' == '3.9'
FAILED test/test_api/test_environment.py::test_versions[3.7] - AssertionError: assert '3.7' == '3.9'
FAILED test/test_api/test_environment.py::test_versions[3.8] - AssertionError: assert '3.8' == '3.9'
FAILED test/test_inference/test_sys_path.py::test_venv_and_pths - AssertionError: assert ['/tmp/pytest...py:from_func'] == ['/tmp/pytest...py:from_func']
============================================================= 4 failed, 3787 passed, 90 skipped, 5 xfailed in 103.03s (0:01:43) =============================================================

@davidhalter
Copy link
Owner

davidhalter commented Mar 25, 2024

This patch is definitely wrong, because it disables multi Python version Jedi.

I'm very confused what you want to do and where you have issues. It's also not better that there are now a lot of different pytest outputs for different versions that point to different potential problems.

@kloczek
Copy link
Author

kloczek commented Mar 25, 2024

This patch is definitely wrong, because it disables multi Python version Jedi.

Which is a bit useless in typical OS distribution which tries provide proper exact python major version support.
If there is no during testing anything else than executable name taken from sys.executable probably better would be skip those units.
Issue in this case is that you assumed that python executable name will be versioned which is not typical case. The same is in case of of other pyton versions executables. Current procedure blindly assumes that those executables are available (there is no checking are they available).

I'm not trying to tell that this patch which I've copied is correct but it is OK typical distro packages build procedure conditions.
In other words that patch is typical JFDI solution and I think that it would be good to have some modification of current testing procedure which may be working OOTB in such conditions. Dropping that patch I've only presented in which direction those conditions are going.

I'm very confused what you want to do and where you have issues. It's also not better that there are now a lot of different pytest outputs for different versions that point to different potential problems.

Yes, because in mean time I've moved to python 3.9 and latest pytest 8.1.1.

@davidhalter
Copy link
Owner

The point is that everything currently works in CI. It works on Windows, Ubuntu and MacOS and probably most other Linux derivates (since I haven't had any complaints except yours). So I really don't know what to do here and I still don't know what the problem is. I'm closing.

@kloczek
Copy link
Author

kloczek commented Mar 26, 2024

The point is that everything currently works in CI.

Point is that I'm not been reporting something what happens in this repo CI and if you will look closer on fedora spec files you can find few units excluded because the yare failing https://src.fedoraproject.org/rpms/python-jedi/blob/rawhide/f/python-jedi.spec

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

2 participants