Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The conda environment doesn't work with test explorer #19873

Closed
xarpy opened this issue Sep 23, 2022 · 12 comments
Closed

The conda environment doesn't work with test explorer #19873

xarpy opened this issue Sep 23, 2022 · 12 comments
Assignees
Labels
area-testing info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@xarpy
Copy link

xarpy commented Sep 23, 2022

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:

  1. 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.languageServer setting: 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

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 23, 2022
@ezra-en
Copy link

ezra-en commented 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': false and see if that works. If so, this may be a duplicate of #19871.

@xarpy
Copy link
Author

xarpy commented 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
Copy link
Author

xarpy commented Oct 7, 2022

Hi @EzraEn1 and @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 @DonJayamanne , any suggestions?

@karrtikr
Copy link

karrtikr commented Oct 7, 2022

This might be that when run in VS Code it is not running in a activated environment. Can you try this?

  1. Anaconda prompt and cd to your workspace.
  2. Activate the environment using conda activate
  3. Start VS Code using code .

related #10626

If that doesn't work, please change the setting terminal.integrated.inheritEnv to false as outlined in https://code.visualstudio.com/updates/v1_36#_launch-terminals-with-clean-environments.

@karrtikr
Copy link

karrtikr commented Oct 7, 2022

Also, can you run

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

in VSCode terminal and send me the output. Make sure to expand ~.

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Oct 7, 2022
@xarpy
Copy link
Author

xarpy commented Oct 12, 2022

This might be that when run in VS Code it is not running in a activated environment. Can you try this?

  1. Anaconda prompt and cd to your workspace.
  2. Activate the environment using conda activate
  3. Start VS Code using code .

related #10626

If that doesn't work, please change the setting terminal.integrated.inheritEnv to false as outlined in https://code.visualstudio.com/updates/v1_36#_launch-terminals-with-clean-environments.

Hi @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::
Gravação de tela de 11-10-2022 21_42_29

@karrtikr karrtikr removed the info-needed Issue requires more information from poster label Oct 12, 2022
@xarpy
Copy link
Author

xarpy commented Oct 12, 2022

Also, can you run

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

in VSCode terminal and send me the output. Make sure to expand ~.

conda run -n project_name --no-capture-output --live-stream python ~/.vscode/extensions/ms-python.python-2022.16.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.0/pythonFiles/testing_tools/run_adapter.py  pytest -- --rootdir . -s --cache-clear
>>>PYTHON-EXEC-OUTPUT
usage: /home/xarpy/.vscode/extensions/ms-python.python-2022.16.0/pythonFiles/testing_tools/run_adapter.py
       [-h] {discover} ...
/home/xarpy/.vscode/extensions/ms-python.python-2022.16.0/pythonFiles/testing_tools/run_adapter.py: error: argument cmd: invalid choice: 'pytest' (choose from 'discover')
<<<PYTHON-EXEC-OUTPUT
ERROR conda.cli.main_run:execute(49): `conda run python /home/xarpy/.vscode/extensions/ms-python.python-2022.16.0/pythonFiles/get_output_via_markers.py /home/xarpy/.vscode/extensions/ms-python.python-2022.16.0/pythonFiles/testing_tools/run_adapter.py pytest -- --rootdir . -s --cache-clear` failed. (See above for error)

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
Copy link

karrtikr commented 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
Copy link

karrtikr commented 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.

@karrtikr karrtikr assigned eleanorjboyd and unassigned karrtikr Nov 9, 2022
@karrtikr karrtikr changed the title The conda environment doesn't work with debugger or test explorer. The conda environment doesn't work with test explorer Nov 9, 2022
@karrtikr
Copy link

@xarpy Can you run the following command instead of #19873 (comment)?

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 discover pytest -- --rootdir . -s --cache-clear

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Nov 14, 2022
@karrtikr
Copy link

karrtikr commented Nov 14, 2022

@xarpy Also try to open a new terminal and install pytest again:

python -m pip install pytest

Ensure conda environment is activated before the above command is run, should look something similar to:
image

@karrtikr karrtikr self-assigned this Nov 14, 2022
@karrtikr
Copy link

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.

@karrtikr karrtikr closed this as not planned Won't fix, can't repro, duplicate, stale Dec 14, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

4 participants