question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImportError when debugging test in vscode

See original GitHub issue

Environment 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.

  1. XXX

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
cnarvaezmelicommented, Dec 9, 2020

Hey, the last comment was solved when I commented a line in the testing configuration in setup.cfg

[aliases]
test=pytest

# [tool:pytest]
# addopts = --verbose --junit-xml=report.xml --cov --cov-report=xml:coverage.xml --log-cli-level=10

The --cov is the one generating this behavior.

0reactions
brettcannoncommented, Apr 21, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Import errors when debugging Python unit tests in VSCode
Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was...
Read more >
Debugging a Containerized Django App in VS Code
In this tutorial, we'll show you how to configure Visual Studio Code (VS Code) to debug a Django app running inside of Docker....
Read more >
VSCode Debugging Import Errors. How to determine ... - Reddit
I am building some unit tests in VSCode with pytest. ... running the pytest debug through the extension causes ImportErrors like this:
Read more >
debug python test in vscode
Unable to import 'someLibrary.someModule' pylint(import-error) The problem might arise due to the multiple Python installations. Basically you have installed a ...
Read more >
Debugging Your Unit Test Suite in Python | Capital One
If you run your tests with pytest --pdb, it will automatically drop into a debugger on every test that fails or has an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found