Repository navigation
Closed
Labels
area-testingbugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from posterneeds PRReady to be worked onverifiedVerification succeeded
Milestone
Description
Type: Bug
Behaviour
vscode-python uses random conda binary for failed pytest discovery.
Steps to reproduce:
- Install several miniconda distributions into separate directories in ~/miniconda3, ~/miniconda5, ~/minicondax86
- Create a development environment with conda and pytest "conda create -n condarun pytest conda"
- Set conda path in settings to `"python.condaPath": "/miniconda3/bin/conda",
- Select new environment, note conda search in
Output (Python)window
2024-12-11 11:17:15.171 [info] Native locator: Refresh started
2024-12-11 11:17:15.187 [info] Conda environment manager found at: /Users/dholth/miniconda3/bin/conda
2024-12-11 11:17:15.221 [info] Conda environment manager found at: /Users/dholth/miniconda5/bin/conda
2024-12-11 11:17:15.223 [info] Conda environment manager found at: /Users/dholth/minicondax86/bin/conda
2024-12-11 11:17:15.224 [info] Conda environment manager found at: /Users/dholth/miniforge3/bin/conda
2024-12-11 11:17:15.253 [info] Native locator: Refresh finished in 82 ms
- Set up, discover pytest. Observe
Output (Python)window using random conda binary/Users/dholth/miniforge3/bin/condainstead of"python.condaPath"
2024-12-11 11:18:24.774 [error] getActivatedEnvironmentVariables [Error: Command failed: /Users/dholth/miniforge3/bin/conda run -n pupa --no-capture-output python /Users/dholth/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py /Users/dholth/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/printEnvVariables.py
Diagnostic data
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
Note that /Users/dholth/minicondax86/bin/conda is used below. I want it to use the configured conda, not a randomly discovered, very outdated one.
2024-12-11 11:31:38.856 [info] Native locator: Refresh started
2024-12-11 11:31:38.872 [info] Conda environment manager found at: /Users/dholth/miniconda3/bin/conda
2024-12-11 11:31:38.935 [info] Conda environment manager found at: /Users/dholth/miniforge3/bin/conda
2024-12-11 11:31:38.936 [info] Conda environment manager found at: /Users/dholth/miniconda5/bin/conda
2024-12-11 11:31:38.939 [info] Conda environment manager found at: /Users/dholth/minicondax86/bin/conda
2024-12-11 11:31:38.973 [info] Native locator: Refresh finished in 116 ms
2024-12-11 11:31:41.979 [info] Discover tests for workspace name: conda-pupa - uri: /Users/dholth/prog/conda-pupa
2024-12-11 11:31:41.979 [info] Running discovery for pytest using the new test adapter.
2024-12-11 11:31:41.980 [info] Python interpreter path: ~/miniconda3/envs/pupa/bin/python
2024-12-11 11:31:41.981 [info] Setting environment variable _CE_M in collection to {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-12-11 11:31:41.982 [info] Setting environment variable XML_CATALOG_FILES in collection to file:///Users/dholth/miniconda3/envs/pupa/etc/xml/catalog file:///etc/xml/catalog file:///Users/dholth/miniconda3/envs/pupa/etc/xml/catalog file:///etc/xml/catalog {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-12-11 11:31:41.982 [info] Setting environment variable CONDA_ROOT in collection to /Users/dholth/miniconda3 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-12-11 11:31:41.982 [info] Setting environment variable CONDA_PREFIX in collection to /Users/dholth/miniconda3/envs/pupa {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-12-11 11:31:41.982 [info] Setting environment variable CONDA_PROMPT_MODIFIER in collection to (pupa) {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-12-11 11:31:41.982 [info] Setting environment variable CONDA_STACKED_3 in collection to true {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-12-11 11:31:41.982 [info] Setting environment variable _CE_CONDA in collection to {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-12-11 11:31:41.982 [info] Setting environment variable CONDA_SHLVL in collection to 3 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-12-11 11:31:41.982 [info] Setting environment variable XPC_SERVICE_NAME in collection to 0 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-12-11 11:31:41.982 [info] Setting environment variable CONDA_DEFAULT_ENV in collection to pupa {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-12-11 11:31:41.982 [info] Prepending environment variable PATH in collection with /Users/dholth/miniconda3/envs/pupa/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-12-11 11:31:41.982 [info] Setting environment variable CONDA_PREFIX_2 in collection to /Users/dholth/miniconda3/envs/pupax {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-12-11 11:31:41.982 [info] Prepending environment variable PS1 in collection with (pupa) {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2024-12-11 11:31:41.985 [info] All environment variables set for pytest discovery:
...
2024-12-11 11:31:41.988 [info] > ~/minicondax86/bin/conda run -n pupa --no-capture-output python ~/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/printEnvVariables.py
2024-12-11 11:31:41.988 [info] shell: bash
2024-12-11 11:31:42.711 [error] getActivatedEnvironmentVariables [Error: Command failed: /Users/dholth/minicondax86/bin/conda run -n pupa --no-capture-output python /Users/dholth/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py /Users/dholth/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/printEnvVariables.py
EnvironmentLocationNotFound: Not a conda environment: /Users/dholth/minicondax86/envs/pupa
at genericNodeError (node:internal/errors:984:15)
at wrappedFn (node:internal/errors:538:14)
at ChildProcess.exithandler (node:child_process:423:12)
at ChildProcess.emit (node:events:531:35)
at maybeClose (node:internal/child_process:1105:16)
at ChildProcess._handle.onexit (node:internal/child_process:305:5)] {
code: 1,
killed: false,
signal: null,
cmd: '/Users/dholth/minicondax86/bin/conda run -n pupa --no-capture-output python /Users/dholth/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py /Users/dholth/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/printEnvVariables.py'
}
2024-12-11 11:31:42.714 [info] > ~/minicondax86/bin/conda run -n pupa --no-capture-output python ~/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py -m pytest -p vscode_pytest --collect-only .
2024-12-11 11:31:42.714 [info] cwd: .
2024-12-11 11:31:43.049 [error]
EnvironmentLocationNotFound: Not a conda environment: /Users/dholth/minicondax86/envs/pupa
2024-12-11 11:31:43.083 [error] Subprocess exited unsuccessfully with exit code 1 and signal null on workspace /Users/dholth/prog/conda-pupa.
2024-12-11 11:31:43.083 [error] Subprocess exited unsuccessfully with exit code 1 and signal null on workspace /Users/dholth/prog/conda-pupa. Creating and sending error discovery payload
2024-12-11 11:31:43.083 [error] pytest test discovery error for workspace: /Users/dholth/prog/conda-pupa
The python test process was terminated before it could exit on its own, the process errored with: Code: 1, Signal: null for workspace /Users/dholth/prog/conda-pupa
Extension version: 2024.20.0
VS Code version: Code 1.95.3 (Universal) (f1a4fb101478ce6ec82fe9627c43efbf9e98c813, 2024-11-13T14:50:04.152Z)
OS version: Darwin arm64 24.1.0
Modes:
- Python version (& distribution if applicable, e.g. Anaconda): 3.12.5
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda 24.11.0
- Value of the
python.languageServersetting: Default
User Settings
condaPath: "/Users/dholth/miniconda3/bin/conda"
languageServer: "Pylance"
testing
• pytestArgs: "python.testing.pytestArgs": [
"--no-cov",
"--basetemp=/tmp/pytesttmp-conda"
],
• pytestEnabled: true
Installed Extensions
| Extension Name | Extension Id | Version |
|---|---|---|
| Azure Repos | ms-vscode.azure-repos | 0.40.0 |
| Black Formatter | ms-python.black-formatter | 2024.4.0 |
| Even Better TOML | tamasfe.even-better-toml | 0.19.2 |
| GitHub Repositories | GitHub.remotehub | 0.64.0 |
| GitLens — Git supercharged | eamodio.gitlens | 16.0.5 |
| JavaScript Debugger | ms-vscode.js-debug | 1.95.3 |
| JavaScript Debugger Companion Extension | ms-vscode.js-debug-companion | 1.1.3 |
| Pylance | ms-python.vscode-pylance | 2024.12.1 |
| Python | ms-python.python | 2024.20.0 |
| Python Debugger | ms-python.debugpy | 2024.12.0 |
| Remote - SSH | ms-vscode-remote.remote-ssh | 0.115.1 |
| Remote - SSH: Editing Configuration Files | ms-vscode-remote.remote-ssh-edit | 0.87.0 |
| Remote Explorer | ms-vscode.remote-explorer | 0.4.3 |
| Remote Repositories | ms-vscode.remote-repositories | 0.42.0 |
| Rewrap | stkb.rewrap | 1.16.3 |
| Ruff | charliermarsh.ruff | 2024.56.0 |
| Table Visualizer for JavaScript Profiles | ms-vscode.vscode-js-profile-table | 1.0.10 |
| Todo Tree | Gruntfuggly.todo-tree | 0.0.226 |
| YAML | redhat.vscode-yaml | 1.15.0 |
System Info
| Item | Value |
|---|---|
| CPUs | Apple M1 Pro (10 x 2400) |
| GPU Status | 2d_canvas: enabled canvas_oop_rasterization: enabled_on direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off video_decode: enabled video_encode: enabled webgl: enabled webgl2: enabled webgpu: enabled webnn: disabled_off |
| Load (avg) | 1, 2, 3 |
| Memory (System) | 16.00GB (0.07GB free) |
| Process Argv | . --crash-reporter-id e18e76d9-d573-4f56-8c99-77786b05ef14 |
| Screen Reader | no |
| VM | 0% |
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805:30301674
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
2i9eh265:30646982
962ge761:30959799
pythonnoceb:30805159
pythonmypyd1:30879173
2e7ec940:31000449
pythontbext0:30879054
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
dvdeprecation:31068756
dwnewjupytercf:31046870
nativerepl2:31139839
pythonrstrctxt:31112756
nativeloc1:31192215
cf971741:31144450
iacca1:31171482
notype1:31157159
5fd0e150:31155592
dwcopilot:31170013
stablechunks:31184530
Metadata
Metadata
Assignees
Labels
area-testingbugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from posterneeds PRReady to be worked onverifiedVerification succeeded
Activity
eleanorjboyd commentedon Dec 11, 2024
Anthony Kim (@anthonykim1) thoughts here?
gandhis1 commentedon Dec 17, 2024
Karthik Nadig (@karthiknadig) I'm seeing a similar thing in #24627 to here, in that it uses a seemingly random conda binary. On older versions of the extension, it would use the global conda, and then now it uses some one located in another repo. That said, I don't think that is the proximate cause of my issue, rather that it's referencing the environment by name (
-n) instead of path (-p).github-actions commentedon Jan 19, 2025
Hey Eleanor Boyd (@eleanorjboyd), this issue might need further attention.
Daniel Holth (@dholth), you can help us out by closing this issue if the problem no longer exists, or adding more information.
dholth commentedon Jan 20, 2025
The issue is still a problem. The "random conda executable" doesn't find tests. This is especially relevant to me since I'm always dealing with development versions of conda that might not be 100% working.
Great idea to use -p (environment path) and never -n (name) Siddhartha Gandhi (@gandhis1)
eleanorjboyd commentedon Feb 7, 2025
nvm ignore this message I found the issue
eleanorjboyd commentedon Feb 7, 2025
Karthik Nadig (@karthiknadig) - question for you since it seems we are not picking up the conda path if set. I am using
createActivatedEnvironmentfunction here. Should I check for the presence of the conda setting and then use the Conda command there if it exists? Is there a more formalized way to make sure that is correct?improve logging for python testing (#24799)
karthiknadig commentedon Feb 7, 2025
This might be a bug in the
CondaExecutionService, it should be the thing that picks this up.eleanorjboyd commentedon Feb 7, 2025
so
createActivatedEnvironmentwill callCondaExecutionService?karthiknadig commentedon Feb 7, 2025
Yes, for conda environments,
createActivatedEnvironmentwill callcreateCondaExecutionService. There we get the environment details for the currently selected interrepter, and build the activation command.jpcorreia99 commentedon Feb 8, 2025
hey folks, +1 on that we should use -p (environment path) and never -n (name). This is causing issues when using relocated conda envs that the local conda installation may not be aware of.
Karthik Nadig (@karthiknadig) is there any way of plugging into the extension API and forcing -p usage?
Also echoing what you had discovered in this issue #24627 (comment), when using version
2024.0.1of the extension it all works perfectly fine! That is, commands are run with-pand it uses the python interpreter from mypython.defaultInterpreterPathconfjpcorreia99 commentedon Feb 11, 2025
hey Karthik Nadig (@karthiknadig) I've looked at what triggers this behaviour and found this code
https://github.com/microsoft/vscode-python/blame/b4aa112990c7e25f1eb06fb5e2b85418f2f4c4fa/src/client/pythonEnvironments/common/environmentManagers/conda.ts#L567-L571
It depends on if we know the name of the env, but it seems like that field is always populated, no matter what is done. This causes issues in even more use cases than what I've reported above:
1 -If we have two anonymous environments with the same name in different folders
by using conda -n my-env it'll always use the first env.
2 - Some times people avoid actually activating their conda envs when using conda-pack https://github.com/conda/conda-pack
This is because the activation scripts are known to be flaky and not very reliable
3 - The environment may have been created by a conda-compliant replacement
Therefore conda itself is not aware of it by name but can work with it properly using the path. This is the case of hawk or frankly anyone building their own conda package manager on top of rattler.
Some of these points are also hinted at #24627 (comment) , and supported by a conda maintainer in #24585 (comment)
Always use environment path when running conda environment commands (#…
jpcorreia99 commentedon Feb 15, 2025
Karthik Nadig (@karthiknadig) Daniel Holth (@dholth) think we can mark this issue as closed whenever a new version of the extension releases with the above PR!
karthiknadig commentedon Feb 18, 2025
Pre-release version
2025.1.2025021801should have it.