Description
Environment data
- Language Server version: 2021.5.3 (pyright 1f57ad5c) starting
- OS and version: OSX 11.2.3 Big Sur
- Python version: 3.8.x installed via asdf
vscode
- Version: 1.56.2
- Commit: 054a9295330880ed74ceaedda236253b4f39a335
- Date: 2021-05-12T17:44:30.902Z (1 wk ago)
- Electron: 12.0.4
- Chrome: 89.0.4389.114
- Node.js: 14.16.0
- V8: 8.9.255.24-electron.0
- OS: Darwin x64 20.3.0
Expected behaviour
I expect vscode/python extension/pylance to respect the pythonPath from .vscode/settings.json and PYTHONPATH from .env when starting up the language server and running tools like the test discovery. Right now it ignores these and uses the python in the system path.
Actual behaviour
So I stumbled into this trying to get the test discovery working. Typically I work in a virtualenv for each project. I create a virtualenv in my project folder with the python3 module
python3 -m venv .
source bin/activate
I have source in a src
folder, tests in tests
and a requirements file installs pytest. Using the following runs my tests perfectly from the command line
PYTHONPATH=lib:tests:src pytest tests
To use this venv in vscode I setup the following .settings file
{
"python.pythonPath": "<full_path_to_project>/bin/python",
"python.envFile": "${workspaceFolder}/.env",
"python.testing.pytestPath": "${workspaceFolder}/bin/pytest",
"python.analysis.extraPaths": ["src", "tests"],
"python.analysis.logLevel": "Trace",
"python.testing.pytestEnabled": true
}
and the .env folder to specify the PYTHONPATH looks like
PYTHONPATH=./src:./tests:./lib
When vscode first starts I see it is using my virtualenv path
Then soon as I click a python file e.g. a test file that kicks off the discovery, the language server boots and uses the first python it finds in the path, overriding my virtualenv one. See logs below
[Info - 14:07:43] Setting pythonPath for service "pylance-issue": "/Users/sgargan/.asdf/installs/python/3.8.8/bin/python3.8"
Of course this has none of my libraries installed and so the test discovery fails completely.
FWICT my vscode environment is setup correctly. if i prefix the ptyest discovery command with my PYTHONPATH and run it in a terminal, it discovers everything correctly. Not really sure why the
Logs
here are the pylance logs
[Info - 14:07:43] Pylance language server 2021.5.3 (pyright 1f57ad5c) starting
[Info - 14:07:43] Server root directory: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist
[Info - 14:07:43] No configuration file found.
[Info - 14:07:43] No pyproject.toml file found.
[Info - 14:07:43] Setting pythonPath for service "pylance-issue": "/Users/sgargan/.asdf/installs/python/3.8.8/bin/python3.8"
[Warn - 14:07:43] stubPath /Users/sgargan/devroot/secdev/pylance-issue/typings is not a valid directory.
[Info - 14:07:43] Assuming Python version 3.8
[Info - 14:07:43] Assuming Python platform Darwin
Search paths for /Users/sgargan/devroot/secdev/pylance-issue
/Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib
/Users/sgargan/devroot/secdev/pylance-issue
/Users/sgargan/devroot/secdev/pylance-issue/src
/Users/sgargan/devroot/secdev/pylance-issue/tests
/Users/sgargan/devroot/secdev/pylance-issue/src
/Users/sgargan/devroot/secdev/pylance-issue/tests
/Users/sgargan/devroot/secdev/pylance-issue/lib
/Users/sgargan/devroot/secdev/pylance-issue/typings
/Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stubs/...
/Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/bundled/stubs
/users/sgargan/.asdf/installs/python/3.8.8/lib/python3.8
/users/sgargan/.asdf/installs/python/3.8.8/lib/python3.8/lib-dynload
/users/sgargan/.local/lib/python3.8/site-packages
/users/sgargan/.asdf/installs/python/3.8.8/lib/python3.8/site-packages
[Info - 14:07:43] Searching for source files
[Info - 14:07:43] Auto-excluding /Users/sgargan/devroot/secdev/pylance-issue
[Info - 14:07:43] No source files found.
[FG] parsing: /Users/sgargan/devroot/secdev/pylance-issue/tests/simple_test.py.py (60ms)
[FG] parsing: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 3ms] (99ms)
[FG] binding: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/builtins.pyi (36ms)
[FG] binding: /Users/sgargan/devroot/secdev/pylance-issue/tests/simple_test.py.py (1ms)
[Info - 14:07:44] Background analysis(1) root directory: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist
[Info - 14:07:44] Background analysis(1) started
Background analysis message: setConfigOptions
Background analysis message: ensurePartialStubPackages
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
Background analysis message: setFileOpened
Background analysis message: setFileOpened
Background analysis message: analyze
[BG(1)] analyzing: /Users/sgargan/devroot/secdev/pylance-issue/tests/simple_test.py ...
[BG(1)] parsing: /Users/sgargan/devroot/secdev/pylance-issue/tests/simple_test.py (35ms)
[BG(1)] parsing: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 2ms] (78ms)
[BG(1)] binding: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/builtins.pyi (35ms)
[BG(1)] binding: /Users/sgargan/devroot/secdev/pylance-issue/tests/simple_test.py (1ms)
[BG(1)] checking: /Users/sgargan/devroot/secdev/pylance-issue/tests/simple_test.py ...
[BG(1)] parsing: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/typing.pyi [fs read 599ms] (638ms)
[BG(1)] binding: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/typing.pyi (10ms)
[BG(1)] parsing: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi [fs read 1ms] (7ms)
[BG(1)] binding: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi (1ms)
[BG(1)] parsing: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/typing_extensions.pyi [fs read 0ms] (2ms)
[BG(1)] binding: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/typing_extensions.pyi (1ms)
[BG(1)] parsing: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/__init__.pyi [fs read 0ms] (5ms)
[BG(1)] binding: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/__init__.pyi ...
[BG(1)] parsing: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/async_case.pyi [fs read 0ms] (1ms)
[BG(1)] binding: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/async_case.pyi (0ms)
[BG(1)] parsing: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/loader.pyi [fs read 0ms] (1ms)
[BG(1)] binding: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/loader.pyi (1ms)
[BG(1)] parsing: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/main.pyi [fs read 0ms] (2ms)
[BG(1)] binding: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/main.pyi (1ms)
[BG(1)] parsing: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/runner.pyi [fs read 0ms] (2ms)
[BG(1)] binding: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/runner.pyi (1ms)
[BG(1)] parsing: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/signals.pyi [fs read 0ms] (1ms)
[BG(1)] binding: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/signals.pyi (0ms)
[BG(1)] parsing: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/suite.pyi [fs read 1ms] (3ms)
[BG(1)] binding: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/suite.pyi (1ms)
[BG(1)] binding: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/__init__.pyi (16ms)
[BG(1)] parsing: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/case.pyi [fs read 0ms] (10ms)
[BG(1)] binding: /Users/sgargan/.vscode/extensions/ms-python.vscode-pylance-2021.5.3/dist/typeshed-fallback/stdlib/unittest/case.pyi (8ms)