ImportError when debugging test in vscode
See original GitHub issueEnvironment data
- VS Code version: 1.48.2
- Extension version (available under the Extensions sidebar): 2020.8.103604
- OS and version: Windows 10 Enterprise 10.0.17134
- Python version (& distribution if applicable, e.g. Anaconda): 3.7.3
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): conda
- Relevant/affected Python packages and their versions: pytest 6.0.1, pandas 0.24.2, numpy 1.16.2
- Relevant/affected Python-related VS Code extensions and their versions: no idea
- Value of the
python.languageServer
setting: no idea
[NOTE: If you suspect that your issue is related to the Microsoft Python Language Server (python.languageServer: 'Microsoft'
), please download our new language server Pylance from the VS Code marketplace to see if that fixes your issue]
Expected behaviour
Expect that breakpoint set in script called by test to work with no errors, since it works fine outside of debug mode.
Actual behaviour
I get an ImportError
when the package is clearly present within my conda environment.
Steps to reproduce:
I have two files example1.py
and test_example1.py
. I also have the necessary extensions for debugging python and use of pytest installed. I’m, using version 1.48.2 of VSCode.
example1.py
contains a simple import:
import pandas as pd
test_example1.py
contains a dummy test which imports example1
as a module:
import pytest
def test_example_1():
import example1
assert True
Above line 3 of test_example1.py
I see a couple of options appear, namely “Run Test” and “Debug Test”:
[![enter image description here][1]][1]
Clicking on “Run Test” I get no errors in the “OUTPUT” window:
============================= test session starts =============================
platform win32 -- Python 3.7.3, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: d:\project
collected 1 item
test_example1.py . [100%]
- generated xml file: C:\Users\aboufira\AppData\Local\Temp\tmp-24288qcdiq9isFmog.xml -
============================== 1 passed in 0.67s ==============================
However, if I place a breakpoint on line 5 in test_example_1.py
and click on “Debug Test” I get an error:
Exception has occurred: ImportError
Missing required dependencies ['numpy']
File "D:\project\example1.py", line 1, in <module>
import pandas as pd
File "D:\project\test_example1.py", line 4, in test_example_1
import example1
Doing a conda list numpy
in my current environment in the terminal window reveals that conda is available, so I don’t understand why this error occurs.
- XXX
Logs
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
XXX
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
Hey, the last comment was solved when I commented a line in the testing configuration in setup.cfg
The
--cov
is the one generating this behavior.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.