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.

Python extension unittest discovery can't import cupy

See original GitHub issue

Issue Type: Bug

Behaviour

Expected vs. Actual

Expected: Tests to be discovered correctly using unittest

Actual: ModuleNotFoundError: No module named 'cupy' in Python output on test discovery, no tests discovered.

Commenting out import cupy allows tests to be discovered with import numpy and import skimage.draw in my actual use case.

Steps to reproduce:

  1. Create an Anaconda environment with cupy
  2. Select env from (1) as interpreter in VSCode
  3. Create a file src.py with import cupy
  4. Create a file test_src.py with from src import *
  5. Add the following to project settings.json:
"python.testing.unittestArgs": ["-v", "-s", ".", "-p", "test_*.py"],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
  1. Test discovery should fail at this point with a ModuleNotFoundError: No module named 'cupy', including traceback.

Running test discovery at the command line works as expected using

python -m unittest discover -v -s . -p test_*.py

Commenting out import cupy allows discovery to proceed.

What’s really interesting about this is I don’t need any actual tests or to use import unittest to reproduce the issue.

Diagnostic data

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


defaultLS: {"defaultLSType":"Pylance"}

downloadLanguageServer: true

envFile: "<placeholder>"

venvPath: "<placeholder>"

venvFolders: "<placeholder>"

condaPath: "<placeholder>"

pipenvPath: "<placeholder>"

poetryPath: "<placeholder>"

languageServer: "Pylance"

linting
• enabled: true
• cwd: "<placeholder>"
• Flake8Args: "<placeholder>"
• flake8Enabled: false
• flake8Path: "<placeholder>"
• lintOnSave: true
• banditArgs: "<placeholder>"
• banditEnabled: false
• banditPath: "<placeholder>"
• mypyArgs: "<placeholder>"
• mypyEnabled: false
• mypyPath: "<placeholder>"
• pycodestyleArgs: "<placeholder>"
• pycodestyleEnabled: false
• pycodestylePath: "<placeholder>"
• prospectorArgs: "<placeholder>"
• prospectorEnabled: false
• prospectorPath: "<placeholder>"
• pydocstyleArgs: "<placeholder>"
• pydocstyleEnabled: false
• pydocstylePath: "<placeholder>"
• pylamaArgs: "<placeholder>"
• pylamaEnabled: false
• pylamaPath: "<placeholder>"
• pylintArgs: "<placeholder>"
• pylintPath: "<placeholder>"

sortImports
• args: "<placeholder>"
• path: "<placeholder>"

formatting
• autopep8Args: "<placeholder>"
• autopep8Path: "<placeholder>"
• provider: "black"
• blackArgs: "<placeholder>"
• blackPath: "<placeholder>"
• yapfArgs: "<placeholder>"
• yapfPath: "<placeholder>"

testing
• cwd: "<placeholder>"
• debugPort: 3000
• nosetestArgs: "<placeholder>"
• nosetestsEnabled: undefined
• nosetestPath: "<placeholder>"
• promptToConfigure: true
• pytestArgs: "<placeholder>"
• pytestEnabled: false
• pytestPath: "<placeholder>"
• unittestArgs: "<placeholder>"
• unittestEnabled: true
• autoTestDiscoverOnSaveEnabled: true

terminal
• activateEnvironment: true
• executeInFileDir: "<placeholder>"
• launchArgs: "<placeholder>"

experiments
• enabled: false
• optInto: []
• optOutFrom: []

tensorBoard
• logDirectory: "<placeholder>"

Extension version: 2022.4.0 VS Code version: Code 1.66.0 (e18005f0f1b33c29e81d732535d8c0e47cafb0b5, 2022-03-30T05:50:14.623Z) OS version: Windows_NT x64 10.0.19041 Restricted Mode: No

System Info
Item Value
CPUs Intel® Core™ i7-9750H CPU @ 2.60GHz (12 x 2592)
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
oop_rasterization: enabled
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
Load (avg) undefined
Memory (System) 15.71GB (4.04GB free)
Process Argv –folder-uri file:///d%3A/repos/uabrc.github.io --crash-reporter-id c8e5394e-cde4-4439-b1c1-1599e605633a
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vstes627:30244334
pythonvspyl392:30443607
pythontb:30283811
pythonvspyt551cf:30345471
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscorecescf:30445987
pythondataviewer:30285071
vscod805cf:30301675
pythonvspyt200:30340761
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
vsc1dst:30438360
pythonvs932:30410667
wslgetstarted:30449410
vsclayoutctrt:30451275
pythonvsnew555:30457759
vscscmwlcmc:30438804
vscgsvidc:30447482
cppdebug:30465021
pynewfile477:30463512

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
EliahKagancommented, Apr 6, 2022

This works for me. After deliberately bringing back the problem by clearing the value of python.condaPath in my user settings, I installed v2022.5.2099471260-dev obtained by that link, and the problem went away again (with python.condaPath still no longer specified).

Thanks!

0reactions
karrtikrcommented, Apr 6, 2022

Thanks everyone, https://github.com/microsoft/vscode-python/suites/5947251954/artifacts/203903588 contains a fix for the issue where everything should ideally work without setting python.condaPath. You can use Extension: Install from VSIX command to install it. Feel free to give it a try and let me know if it’s still a issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python unittest discovery can not import source code
You need to configure the PYTHONPATH in the .env file. An example of when to use PYTHONPATH would be if you have source...
Read more >
unittest — Unit testing framework — Python 3.11.1 ...
For example foo/bar/baz.py will be imported as foo.bar.baz . If you have a package installed globally and attempt test discovery on a different...
Read more >
unittest2 - PyPI
Feature parity with unittest in Python 2.7 RC 1. 2010/05/09 - 0.4.1. If test discovery imports a module from the wrong location (usually...
Read more >
Setting up unit tests in Python with VSCode - YouTube
Using macOS Catalina Version 10.15.7Using VS Code Version: 1.53.0https://code.visualstudio.com/docs/ python /testing.
Read more >
Testing Extensions with Python — kit-manual 104.0 ...
It supports two types of testing: * python tests ( unittest with ... import omni.kit.test # Import extension python module we are testing ......
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