Repository navigation
Activate environment before debugging tests #4300
Copy link
Copy link
Closed
Labels
area-debuggingarea-environmentsFeatures relating to handling interpreter environmentsFeatures relating to handling interpreter environmentsarea-testingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugverifiedVerification succeededVerification succeeded
Milestone
Description
- VS Code version: 1.30.2
- Extension version (available under the Extensions sidebar): 2019.1.0
- OS and version: Windows 7
- Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.1, anaconda
- Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
- Relevant/affected Python packages and their versions: numpy
Expected behaviour
Test runs in debug mode
Actual behaviour
When "Debug Test" is selected from within the editor above a unittest the known error message from #3330 is shown
Steps to reproduce:
- install anaconda
- create py3.6 and py3.7 environments
- install vscode, python extension
- open a folder of a python project using numpy with testing, enable testing, select the environment and click "Debug Test" above a test method of a test case from within the editor.
Logs
============================= test session starts =============================
platform win32 -- Python 3.7.1, pytest-4.2.0, py-1.7.0, pluggy-0.8.1
benchmark: 3.2.2 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: c:\project, inifile:
plugins: cov-2.6.1, benchmark-3.2.2
=================================== ERRORS ====================================
__________________ ERROR collecting tests/test_data_prep.py ___________________
ImportError while importing test module 'c:\project\tests\test_data_prep.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
C:\Users\XXXXX\AppData\Local\Continuum\anaconda3\envs\project\lib\site-packages\numpy\core\__init__.py:16: in <module>
from . import multiarray
E ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
During handling of the above exception, another exception occurred:
tests\test_data_prep.py:1: in <module>
import numpy as np
C:\Users\XXXXX\AppData\Local\Continuum\anaconda3\envs\project\lib\site-packages\numpy\__init__.py:142: in <module>
from . import add_newdocs
C:\Users\XXXXX\AppData\Local\Continuum\anaconda3\envs\project\lib\site-packages\numpy\add_newdocs.py:13: in <module>
from numpy.lib import add_newdoc
C:\Users\XXXXX\AppData\Local\Continuum\anaconda3\envs\project\lib\site-packages\numpy\lib\__init__.py:8: in <module>
from .type_check import ...
generated xml file: C:\Users\XXXXX\AppData\Local\Temp\tmp-10040Ua1sUDOhID1o.xml
=========================== 1 error in 0.27 seconds ===========================
ERROR: not found: c:\project\tests\test_data_prep.py::TestCustomFeautures::test_compare_name_email
(no name 'c:\\project\\tests\\test_data_prep.py::TestCustomFeautures::test_compare_name_email' in any of [<Module test_data_prep.py>])
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-debuggingarea-environmentsFeatures relating to handling interpreter environmentsFeatures relating to handling interpreter environmentsarea-testingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugverifiedVerification succeededVerification succeeded
Activity
DonJayamanne commentedon Feb 6, 2019
Moritz Bunse (@mbunse) Does it work for you when no run the code without debugging?
mbunse commentedon Feb 6, 2019
Yes. Clicking "Run Test" works as expected.
d3r3kk commentedon Feb 7, 2019
I can reproduce this locally on Windows 10, with the following repo sample:
4300_conda_debug_tests_with_numpy.zip
Anaconda Promptand create an environment like so:conda create -n 4300 pylint numpy pytest autopep8test_compare_name_emailclickRun Test. Observe that it completes successfully.Debug Test, observe the failure.Resulting screen
Output :: Python Test
Debug Console
Developer Tools Window
Click to expand...
cpaulik commentedon Mar 20, 2019
We have a similar issue that during debugging of a script the conda environment is not activated before the script is started in debug mode. Similar to #2862 but in
cmd.exeIt works if the debugging is started a second time using the same internal terminal. Then the conda environment is activated before running the script in debug mode.
I can open a new issue but they all seem to have a similar cause
RoyLarson commentedon Apr 6, 2019
Does this have to do with the below numpy issue?
numpy/numpy#12736
52 remaining items
karrtikr commentedon Jul 28, 2022
Workaround for remote scenarios
In scenarios where it's not possible to launch VSCode via an activated environment, I have captured the instructions in a GIF:
Here're step by step instructions for the example:
Open User Settings (JSON)to open user settings, and append the profile created with:$PATHenvironment variable to figure out the path to conda install. For eg. it could be~/miniconda3or/opt/condain my case.itcarroll commentedon Nov 15, 2022
Haven't had success with proposed workarounds when using the Remote-SSH extension. I wouldn't mind starting in an activated environment, but Kartik Raj (@karrtikr) 's instructions do not appear to effect the shell used by the test-debugger.
dhapolapankaj commentedon Aug 24, 2023
Adding below key:value pair in launch.json file, fixed my problem
"env": {"PATH":"${workspaceFolder}/venv/Scripts/"},Then run below code in any PowerShell terminal to set the execution policy to run PowerShell code
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserIt runs Activate.ps1 (which activates python environment) file in PowerShell debug terminal, before running the python file that has break point.
Activate environment when not using integrated terminal for debugging (…
karrtikr commentedon Sep 11, 2023
Should be fixed in the latest stable release of Python extension, please give it a try.
Activate environment when not using integrated terminal for debugging (…