microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.7k stars 769 forks source link

detected unhandled Python exception in '...extensions/ms-python.vscode-pylance-2024.3.2/dist/bundled/files/get_pytest_options.py' #6295

Open keestux opened 2 weeks ago

keestux commented 2 weeks ago

Environment data

Code Snippet

...

Repro Steps

Just start code and look at output of journalctl -f.

Logs

It seems to have started with 2024.3.2

Excerpt from journalctl

Apr 01 21:39:38 racer python[266141]: detected unhandled Python exception in '/home/kees/.vscode/extensions/ms-python.vscode-pylance-2024.3.2/dist/bundled/files/get_pytest_options.py'
Apr 01 21:39:38 racer python[266142]: detected unhandled Python exception in '/home/kees/.vscode/extensions/ms-python.vscode-pylance-2024.3.2/dist/bundled/files/get_pytest_options.py'
Apr 01 21:39:38 racer abrt-server[266144]: Not saving repeating crash in '/home/kees/.vscode/extensions/ms-python.vscode-pylance-2024.3.2/dist/bundled/files/get_pytest_options.py'
Apr 01 21:39:38 racer abrt-server[266143]: Executable '/home/kees/.vscode/extensions/ms-python.vscode-pylance-2024.3.2/dist/bundled/files/get_pytest_options.py' doesn't belong to any package and ProcessUnpackaged is set to 'no'
Apr 01 21:39:38 racer abrt-server[266143]: 'post-create' on '/var/spool/abrt/Python3-2024-04-01-21:39:38-266141' exited with 1
Apr 01 21:39:38 racer abrt-server[266143]: Deleting problem directory '/var/spool/abrt/Python3-2024-04-01-21:39:38-266141'
...
Aug 24 20:28:34 racer python[11991]: detected unhandled Python exception in '/home/kees/.vscode/extensions/ms-python.vscode-pylance-2024.8.1/dist/bundled/files/get_pytest_options.py'
Aug 24 20:28:34 racer abrt-server[11992]: Executable '/home/kees/.vscode/extensions/ms-python.vscode-pylance-2024.8.1/dist/bundled/files/get_pytest_options.py' doesn't belong to any package and ProcessUnpackaged is set to 'no'
Aug 24 20:28:34 racer abrt-server[11992]: 'post-create' on '/var/spool/abrt/Python3-2024-08-24-20:28:34-11991' exited with 1
Aug 24 20:28:34 racer abrt-server[11992]: Deleting problem directory '/var/spool/abrt/Python3-2024-08-24-20:28:34-11991'
keestux commented 2 weeks ago

A work around is to comment out everything in get_pytest_options.py, or to install python3-pytest.

Of course the code in get_pytest_options.py should be able to handle the absence of _pytest.

import sys
try:
    from _pytest.config import get_config

    c = get_config()
    c.parse(sys.argv)
    print(f"Python classes: {c.getini('python_classes')}")
    print(f"Python files: {c.getini('python_files')}")
    print(f"Python functions: {c.getini('python_functions')}")
except ModuleNotFoundError:
    pass
rchiodo commented 2 weeks ago

The logic currently expects an exception if pytest isn't installed. I suppose we could change the logic and sys.exit(1) instead or something.

keestux commented 2 weeks ago

Can you show me where and how this get_pytest_options.py is used?

rchiodo commented 2 weeks ago

Sorry but it's closed source. The logic is here for somebody else to possibly fix: https://github.com/microsoft/pyrx/blob/41c31cdef2af8e635f05fe78826dfe27d1f38aef/packages/pylance-internal/src/pytest/queryEngine.ts#L36

It just runs the script. If it fails it uses the defaults for pytest.