Repository navigation
The conda environment doesn't work with test explorer #19873
Description
Type: Bug
Behaviour
I participated in some projects that use python version 2.7 and the Pyramid framework. As all my environments are managed through miniconda3, I just create the specific environments for each project from their requirements.
However, I have noticed some instability in the vscode to be able to debug some projects, which use python, since 2 last updates.
Now during some routine tests, as I always had the habit of running the debugger and creating breakpoints, as well as running the tests from the editor, I'm not succeeding anymore.
This my launch.json for the project reference:
{
"configurations": [
{
"name": "Python: Pyramid Application",
"type": "python",
"request": "launch",
"module": "pyramid.scripts.pserve",
"args": ["--reload", "${workspaceFolder}/development.ini"],
"pyramid": true,
"jinja": true,
"justMyCode": true
}
]
}
Trying to run the debugger I can't get any kind of output, but running the Plugin Test Explorer UI + Python Test Explorer, which always worked before, now doesn't work!
Please note that I can activate the python environments created by conda normally from vscode, as well as run all the tests in a terminal:
conda run -n project_name --no-capture-output --live-stream python ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/testing_tools/run_adapter.py pytest -- --rootdir . -s --cache-clear
>>>PYTHON-EXEC-OUTPUT
<<<PYTHON-EXEC-OUTPUT
Traceback (most recent call last):
File "/home/xarpy/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py", line 26, in <module>
runpy.run_path(module, run_name="__main__")
File "/home/xarpy/opt/miniconda3/lib/python3.9/runpy.py", line 288, in run_path
return _run_module_code(code, init_globals, run_name,
File "/home/xarpy/opt/miniconda3/lib/python3.9/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/home/xarpy/opt/miniconda3/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/xarpy/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/testing_tools/run_adapter.py", line 17, in <module>
from testing_tools.adapter.__main__ import parse_args, main
File "/home/xarpy/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/testing_tools/adapter/__main__.py", line 9, in <module>
from . import pytest, report
File "/home/xarpy/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/testing_tools/adapter/pytest/__init__.py", line 7, in <module>
from ._discovery import discover
File "/home/xarpy/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 8, in <module>
import pytest
ModuleNotFoundError: No module named 'pytest'
ERROR conda.cli.main_run:execute(49): `conda run python ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/testing_tools/run_adapter.py pytest -- --rootdir . -s --cache-clear` failed. (See above for error)When running debugpy command with conda run in terminal, for test if conda find the module and package to execute:
conda run -n project_name --no-capture-output --live-stream python ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/lib/python/debugpy/adapter
Content-Length: 137
{"seq": 1, "type": "event", "event": "output", "body": {"category": "telemetry", "output": "ptvsd", "data": {"packageVersion": "1.6.3"}}}Content-Length: 139
{"seq": 2, "type": "event", "event": "output", "body": {"category": "telemetry", "output": "debugpy", "data": {"packageVersion": "1.6.3"}}}Expected vs. Actual
XXX
Steps to reproduce:
- Just create the files, for debugger preffer to pyramid framework, install the plugin Test Explorer UI and try to execute debug or test explorer.
Diagnostic data
- Conda Version: 4.0.14.0
- Python version (& distribution if applicable, e.g. Anaconda): 2.7.18
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
- Value of the
python.languageServersetting: Pylance - VSCode version:
Versão: 1.71.2
Commit: 74b1f979648cc44d385a2286793c226e611f59e7
Data: 2022-09-14T21:12:14.256Z
Electron: 19.0.12
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
SO: Linux x64 5.15.0-48-generic
Em área restrita: No
User Settings
condaPath: "<placeholder>"
languageServer: "Pylance"
linting
• flake8Args: "<placeholder>"
• flake8Enabled: true
formatting
• autopep8Args: "<placeholder>"
testing
• pytestEnabled: true
• autoTestDiscoverOnSaveEnabled: false
Extension version: 2022.14.0
VS Code version: Code 1.71.2 (74b1f979648cc44d385a2286793c226e611f59e7, 2022-09-14T21:12:14.256Z)
OS version: Linux x64 5.15.0-48-generic
Modes:
Sandboxed: No
System Info
| Item | Value |
|---|---|
| CPUs | 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz (16 x 2300) |
| GPU Status | 2d_canvas: enabled canvas_oop_rasterization: disabled_off 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_renderer: enabled_on video_decode: disabled_software video_encode: disabled_software vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: disabled_off |
| Load (avg) | 1, 0, 0 |
| Memory (System) | 15.48GB (8.83GB free) |
| Process Argv | --unity-launch --crash-reporter-id af58d562-3f25-41a2-a7ce-ababeb5e1431 |
| Screen Reader | no |
| VM | 0% |
| DESKTOP_SESSION | ubuntu |
| XDG_CURRENT_DESKTOP | Unity |
| XDG_SESSION_DESKTOP | ubuntu |
| XDG_SESSION_TYPE | x11 |
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vstes627:30244334
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30557514
vsaa593:30376534
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
hb751961:30553087
dsvsc012cf:30540253
azure-dev_surveyone:30548225
2144e591:30553903
fc301958:30573243
Activity
ezra-en commentedon Sep 25, 2022
Seeing as you can run it manually, it might be an issue with the debugger not being able to attach to your miniconda interpreter, or because your code isn't being recognised as your own because you're running it with miniconda. Try debugging with
'justMyCode': falseand see if that works. If so, this may be a duplicate of #19871.xarpy commentedon Sep 29, 2022
Hi @EzraEn1 , one of the approaches suggested in some comments was to downgrade to previous versions of the ms-python package, to version v2022.2.1924087327, This solved my problem partially, but I will test with these recommendations and try to understand the scenarios better.
xarpy commentedon Oct 7, 2022
Hi @EzraEn1 and Kartik Raj (@karrtikr) , the solution with this property does not work, because vsocde does not work in debug mode with the last update and conda, but if you change to the previous version of the ms-python package, as I suggested in the last post, it works, however now tests do not work anymore!
I am currently using the latest version of conda, 22.9.0, but still no success.
Hey Don Jayamanne (@DonJayamanne) , any suggestions?
karrtikr commentedon Oct 7, 2022
This might be that when run in VS Code it is not running in a activated environment. Can you try this?
cdto your workspace.conda activatecode .related #10626
If that doesn't work, please change the setting
terminal.integrated.inheritEnvtofalseas outlined in https://code.visualstudio.com/updates/v1_36#_launch-terminals-with-clean-environments.karrtikr commentedon Oct 7, 2022
Also, can you run
in VSCode terminal and send me the output. Make sure to expand
~.xarpy commentedon Oct 12, 2022
Hi Kartik Raj (@karrtikr), I followed these steps but was not successful, see the recording below, when I tried running vscode with conda enabled manually and accessing the project folder with vscode from the terminal::

xarpy commentedon Oct 12, 2022
But if I run it in the old version, as talked about earlier, the debugger works but the tests don't, only if they are run manually from the terminal.
karrtikr commentedon Nov 9, 2022
Debugger doesn't work as we no longer support debugging for Python below
3.7, please upvote #19559 if you would like to see us bring it back.karrtikr commentedon Nov 9, 2022
For the testing issue it seems we're not able to parse the arguments correctly when run in terminal as it looks like here: #19873 (comment)
Reassigning as that's testing related.
[-]The conda environment doesn't work with debugger or test explorer.[/-][+]The conda environment doesn't work with test explorer[/+]karrtikr commentedon Nov 14, 2022
Renan Penna (@xarpy) Can you run the following command instead of #19873 (comment)?
karrtikr commentedon Nov 14, 2022
Renan Penna (@xarpy) Also try to open a new terminal and install pytest again:
Ensure conda environment is activated before the above command is run, should look something similar to:

karrtikr commentedon Dec 14, 2022
Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on then we will be happy to re-open this issue to pick up where we left off.