question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pytest fails to use the correct conda environment path for testing

See original GitHub issue

Issue Type: Bug

Pytest discover tests

I get error: EnvironmentLocationNotFound: Not a conda environment: C:\Conda\envs\swp10\envs\swp10 because the true path is just; C:\Conda\envs\swp10\


Experiment 'pythonaa' is active
Experiment 'pythonTensorboardExperiment' is active
Experiment 'PythonPyTorchProfiler' is active
Experiment 'pythonDeprecatePythonPath' is active
Experiment 'pythonInterpreterInfoPinned' is active
> conda info --json
> C:\Conda\envs\swp10\python.exe ~\.vscode\extensions\ms-python.python-2022.5.11221002\pythonFiles\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2022.5.11221002\pythonFiles\interpreterInfo.py
> C:\Conda\python.exe ~\.vscode\extensions\ms-python.python-2022.5.11221002\pythonFiles\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2022.5.11221002\pythonFiles\interpreterInfo.py
Python interpreter path: C:\Conda\envs\swp10\python.exe
> conda run -n swp10 --no-capture-output python ~\.vscode\extensions\ms-python.python-2022.5.11221002\pythonFiles\get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.5.11221002/pythonFiles/printEnvVariables.py
> C:\Conda\envs\flights\python.exe ~\.vscode\extensions\ms-python.python-2022.5.11221002\pythonFiles\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2022.5.11221002\pythonFiles\interpreterInfo.py
> C:\Conda\envs\handson\python.exe ~\.vscode\extensions\ms-python.python-2022.5.11221002\pythonFiles\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2022.5.11221002\pythonFiles\interpreterInfo.py
> C:\Conda\envs\refining\python.exe ~\.vscode\extensions\ms-python.python-2022.5.11221002\pythonFiles\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2022.5.11221002\pythonFiles\interpreterInfo.py
Starting Pylance language server.
> conda run -n swp10 --no-capture-output python ~\.vscode\extensions\ms-python.python-2022.5.11221002\pythonFiles\get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.5.11221002/pythonFiles/printEnvVariables.py
> conda run -n swp10 --no-capture-output python ~\.vscode\extensions\ms-python.python-2022.5.11221002\pythonFiles\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2022.5.11221002\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir . -s --cache-clear tests
cwd: .
[ERROR 2022-4-5 14:48:49.500]: Error discovering pytest tests:
 [n [Error]: 
EnvironmentLocationNotFound: Not a conda environment: C:\Conda\envs\swp10\envs\swp10

at ChildProcess.<anonymous> (c:\Users\Varo-local_User\.vscode\extensions\ms-python.python-2022.5.11221002\out\client\extension.js:2:228554)
at Object.onceWrapper (node:events:510:26)
at ChildProcess.emit (node:events:390:28)
at maybeClose (node:internal/child_process:1064:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)]

Steps to reproduce:

  1. Download this repo
  2. Open the test tab on VSCode

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.4
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
  • Value of the python.languageServer setting: Pylance

languageServer: β€œPylance”

linting β€’ enabled: true β€’ cwd: β€œ<placeholder>” β€’ Flake8Args: β€œ<placeholder>” β€’ flake8Enabled: false β€’ flake8Path: β€œ<placeholder>” β€’ lintOnSave: true β€’ banditArgs: β€œ<placeholder>” β€’ banditEnabled: false β€’ banditPath: β€œ<placeholder>” β€’ mypyArgs: β€œ<placeholder>” β€’ mypyEnabled: false β€’ mypyPath: β€œ<placeholder>” β€’ pycodestyleArgs: β€œ<placeholder>” β€’ pycodestyleEnabled: false β€’ pycodestylePath: β€œ<placeholder>” β€’ prospectorArgs: β€œ<placeholder>” β€’ prospectorEnabled: false β€’ prospectorPath: β€œ<placeholder>” β€’ pydocstyleArgs: β€œ<placeholder>” β€’ pydocstyleEnabled: false

β€’ pylamaEnabled: false

formatting

β€’ provider: β€œyapf”

testing β€’ cwd: β€œ<placeholder>” β€’ debugPort: 3000 β€’ nosetestArgs: β€œ<placeholder>” β€’ nosetestsEnabled: undefined β€’ nosetestPath: β€œ<placeholder>” β€’ promptToConfigure: true β€’ pytestArgs: β€œ<placeholder>” β€’ pytestEnabled: true β€’ pytestPath: β€œ<placeholder>” β€’ unittestArgs: β€œ<placeholder>” β€’ unittestEnabled: false β€’ autoTestDiscoverOnSaveEnabled: true

terminal β€’ activateEnvironment: true

experiments β€’ enabled: true β€’ optInto: [] β€’ optOutFrom: []


</p>
</details>


Extension version: 2022.5.11221002
VS Code version: Code 1.66.2 (dfd34e8260c270da74b5c2d86d61aee4b6d56977, 2022-04-11T07:46:01.075Z)
OS version: Windows_NT x64 10.0.17763
Restricted Mode: No

<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|Intel(R) Xeon(R) CPU E5-2697A v4 @ 2.60GHz (8 x 2600)|
|GPU Status|2d_canvas: unavailable_software<br>canvas_oop_rasterization: disabled_off<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: disabled_software<br>multiple_raster_threads: enabled_on<br>oop_rasterization: disabled_off<br>opengl: disabled_off<br>rasterization: disabled_software<br>raw_draw: disabled_off_ok<br>skia_renderer: enabled_on<br>video_decode: disabled_software<br>video_encode: disabled_software<br>vulkan: disabled_off<br>webgl: unavailable_software<br>webgl2: unavailable_software|
|Load (avg)|undefined|
|Memory (System)|64.00GB (48.15GB free)|
|Process Argv|D:\\DV\\VAROModule --crash-reporter-id 4258b87b-5f84-49f0-94bb-91ba84a55f17|
|Screen Reader|no|
|VM|100%|
</details><details>
<summary>A/B Experiments</summary>

vsliv368cf:30146710 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 pythonvspyl392:30443607 pythontb:30283811 pythonptprofiler:30281270 vshan820:30294714 vstes263:30335439 pythondataviewer:30285071 vscod805cf:30301675 pythonvspyt200:30340761 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 vsc1dst:30438360 pythonvs932:30410667 wslgetstarted:30449410 pythonvsnew555:30457759 vscscmwlcmt:30465135 cppdebug:30475216


</details>

<!-- generated by issue reporter -->

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:41

github_iconTop GitHub Comments

2reactions
aaravind100commented, Aug 24, 2022

I have this same problem, but in wsl. The conda environment name is dev162 located at β€œ/home/aravia1/miniconda3/envs/dev162/” but it is looking for the environment at β€œ/home/aravia1/miniconda3/envs/dev162/envs/dev162” and fails.

Experiment 'pythonaacf' is active
LSP Notebooks experiment is enabled
LSP Notebooks interactive window support is enabled
Python interpreter path: ~/miniconda3/envs/dev162/bin/python
Starting Pylance language server.
> conda info --json
> conda run -n dev162 --no-capture-output python ~/.vscode-server/extensions/ms-python.python-2022.12.1/pythonFiles/get_output_via_markers.py ~/.vscode-server/extensions/ms-python.python-2022.12.1/pythonFiles/printEnvVariables.py
> conda run -n dev162 --no-capture-output python ~/.vscode-server/extensions/ms-python.python-2022.12.1/pythonFiles/get_output_via_markers.py ~/.vscode-server/extensions/ms-python.python-2022.12.1/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear tests
cwd: .
[ERROR 2022-7-24 11:58:52.839]: Error discovering pytest tests:
 [n [Error]: 
EnvironmentLocationNotFound: Not a conda environment: /home/aravia1/miniconda3/envs/dev162/envs/dev162


	at ChildProcess.<anonymous> (/home/aravia1/.vscode-server/extensions/ms-python.python-2022.12.1/out/client/extension.js:2:238622)
	at Object.onceWrapper (node:events:510:26)
	at ChildProcess.emit (node:events:390:28)
	at maybeClose (node:internal/child_process:1064:16)
	at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)]
> conda info --json

As weird as it sounds, i just tried creating a symlink at the path β€œ/home/aravia1/miniconda3/envs/dev162/envs/dev162” and the tests gets discovered 🀷.

Symlink:

ln -s ~/miniconda3/envs/dev162/ ~/miniconda3/envs/dev162/envs/dev162

Successful test discovery:

> conda run -n dev162 --no-capture-output python ~/.vscode-server/extensions/ms-python.python-2022.12.1/pythonFiles/get_output_via_markers.py ~/.vscode-server/extensions/ms-python.python-2022.12.1/pythonFiles/printEnvVariables.py
> conda run -n dev162 --no-capture-output python ~/.vscode-server/extensions/ms-python.python-2022.12.1/pythonFiles/get_output_via_markers.py ~/.vscode-server/extensions/ms-python.python-2022.12.1/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear tests
cwd: .
1reaction
karrtikrcommented, Nov 9, 2022

Created a bug on conda: https://github.com/conda/conda/issues/12082, feel free to upvote that to raise priority. Closing in favor of conda.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get VSCode to correctly activate conda when ...
If I run the tests from pytest using VSCode (VSCode installs pytest into the sqlite_test environment using Pip), then I get the following...
Read more >
pytest-workflow β€” pytest-workflow 1.6.0 documentation
Writing workflows is hard. Testing if they are correct is even harder. Testing with bash scripts or other code has some flaws. Is...
Read more >
PyCharm - Configure a conda virtual environment - JetBrains
Ensure that Anaconda or Miniconda is downloaded and installed on your computer, and you're aware of a path to its executable file. Refer...
Read more >
Testing Python in Visual Studio Code
Testing Python in Visual Studio Code including the Test Explorer. ... Use a full path if pytest is located outside the current environment....
Read more >
Python Installation - Conda Install | Google Earth Engine
Print the conda command's help menu to test the Miniconda install. Since Miniconda has not been added to your system's PATH environment variable,Β ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found