Skip to content

Debug test does not load env variables from conda #20680

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

Closed
giacomorebecchi opened this issue Feb 10, 2023 · 8 comments
Closed

Debug test does not load env variables from conda #20680

giacomorebecchi opened this issue Feb 10, 2023 · 8 comments
Assignees
Labels
area-debugging area-environments Features relating to handling interpreter environments triage-needed Needs assignment to the proper sub-team

Comments

@giacomorebecchi
Copy link

Type: Bug

Behaviour

Expected vs. Actual

Expected: if I set the python interpreter for a workspace as a conda env built from an environment.yml file that specifies some environment variables through the variables keyword, I would like to have those variables set when I run code through the Python debugger VSCode extension.

Actual: the env variables are not set when running code from the VSCode debugger.

Note that I experienced the error while debugging tests using pytest.

Steps to reproduce:

  1. Create a conda environment through an environment.yml with variables keyword specifying some env vars
  2. Select as interpeter such a conda env for the workspace
  3. Write a test that checks that the env vars are correctly set
  4. If you run the test from the terminal using pytest, the test passes
  5. If you debug the test, the env vars are not found

Diagnostic data

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


languageServer: "Pylance"

linting
• flake8Args: "<placeholder>"
• flake8Enabled: true

formatting
• provider: "black"

testing
• pytestArgs: "<placeholder>"
• pytestEnabled: true

Extension version: 2023.2.0
VS Code version: Code 1.75.1 (441438abd1ac652551dbe4d408dfcec8a499b8bf, 2023-02-08T21:32:34.589Z)
OS version: Windows_NT x64 10.0.22621
Modes:
Sandboxed: No
Remote OS version: Linux x64 5.15.0-1028-aws

System Info
Item Value
CPUs Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz (8 x 1992)
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: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) undefined
Memory (System) 7.85GB (1.32GB free)
Process Argv --crash-reporter-id 9642e38f-e1aa-4799-ba32-b1383b4b1c29
Screen Reader no
VM 0%
Item Value
Remote SSH: GR.Dev
OS Linux x64 5.15.0-1028-aws
CPUs Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz (2 x 2499)
Memory (System) 7.66GB (6.12GB free)
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492cf:30256860
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
pythondataviewer:30285071
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vsclangdf:30486550
c4g48928:30535728
dsvsc012:30540252
pynewvextcfv2:30660300
azure-dev_surveyone:30548225
vsccc:30610678
pyindex848cf:30577861
nodejswelcome1cf:30587006
2e4cg342:30602488
f6dab269:30613381
pythonsymbol12:30657548

@karrtikr
Copy link

Thanks for the bug report! We just wanted to quickly acknowledge we received it and we will triage this as soon as we can.

@karrtikr
Copy link

Try adding the following configuration to your launch.json file:

{
  "name": "Debug Unit Test",
  "type": "python",
  "request": "launch",
  "purpose": ["debug-test"],
  "console": "integratedTerminal",
},

This makes sure we use integrated terminal instead of internal console when debugging tests, where the environment variables are already loaded.

@karrtikr
Copy link

#8422 should help fix the error when using internal console.

@karrtikr karrtikr added area-debugging info-needed Issue requires more information from poster area-environments Features relating to handling interpreter environments labels Feb 14, 2023
@giacomorebecchi
Copy link
Author

@karrtikr thanks for suggesting a workaround!

@karrtikr karrtikr removed the info-needed Issue requires more information from poster label Feb 14, 2023
@karrtikr
Copy link

@eleanorjboyd @karthiknadig Is there any particular reason why we prefer to use internalConsole as default instead of integratedTerminal when debugging tests. Considering in normal debugging scenarios terminal is used by default.

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Feb 14, 2023
@eleanorjboyd
Copy link
Member

deferring to @karthiknadig for this answer

@karthiknadig
Copy link
Member

Tests are often run in the background. So, we use internalConsole, in an attempt to preserve the manner in which we discover and run tests without debugger.

@karrtikr karrtikr removed the info-needed Issue requires more information from poster label Feb 14, 2023
@karrtikr
Copy link

karrtikr commented Feb 14, 2023

I see, given there's nothing to change, closing this issue in favor of #8422. Feel free to upvote that to raise priority.

@karrtikr karrtikr closed this as not planned Won't fix, can't repro, duplicate, stale Feb 14, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging area-environments Features relating to handling interpreter environments triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

4 participants