Skip to content

VS Code python unittest fails to import modules outside tests folder during debug #21648

@cfframe

Description

@cfframe

Type: Bug

Since earlier this month, attempting to debug Python unittest tests in existing and new projects fails with an error similar to

ModuleNotFoundError: No module named '<file or folder name>'

for any test file trying to import something outside of the tests folder.

A basic project based on guidance in Testing Python in Visual Studio Code can be cloned from https://github.com/cfframe/PythonBasicTest.

Tests will run using the gui, but debugging a test generates this error in the DEBUG CONSOLE:

E
======================================================================
ERROR: test_unittest (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_unittest
Traceback (most recent call last):
  File "C:\Python\3.10.11\lib\unittest\loader.py", line 154, in loadTestsFromName
    module = __import__(module_name)
  File "c:\GitLab\cfframe\BasicTest3\PythonBasicTest\tests\test_unittest.py", line 1, in <module>
    import inc_dec as inc_dec    # The code to test
ModuleNotFoundError: No module named 'inc_dec'


----------------------------------------------------------------------
Ran 1 test in 0.009s

FAILED (errors=1)

Versions:

  • VSCode versions 1.80.1, 1.80.0, 1.79.2, 1.79.1
  • Python 3.10.11, 3.10.6, 3.9.13
  • ms-python.python 2023.12.0
  • ms-python.vscode-pylance 2023.7.20

I have disabled all other extensions to try troubleshooting this.

I have no similar problems with PyCharm on the same projects.

Extension version: 2023.12.0
VS Code version: Code 1.80.1 (74f6148eb9ea00507ec113ec51c489d6ffb4b771, 2023-07-12T17:22:07.651Z)
OS version: Windows_NT x64 10.0.19045
Modes:

System Info
Item Value
CPUs 11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz (8 x 2611)
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
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 15.69GB (6.25GB free)
Process Argv C:\GitLab\cfframe\BasicTest3\PythonBasicTest --crash-reporter-id 679c4d58-dda0-4be6-a133-afbb5e749e9c
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30445986
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
pythonvs932:30410667
py29gd2263:30789496
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
3biah626:30602489
pyind779:30671433
f6dab269:30613381
vscrp:30673768
pythonsymbol12:30671437
showlangstatbar:30737416
vsctsb:30748421
pythonms35:30701012
a2ce3375:30757347
pythonfmttext:30731395
pythoncmvfstrcf:30756944
fixshowwlkth:30771522
hideindicator:30785051
pythongtdpath:30769146
bgfeh915:30780428
pythonnosm12tcf:30779713
pythonidxpt:30784022
pythonnoceb:30776495
h7j2d465:30786200
dsvsc013cf:30789518

Metadata

Metadata

Assignees

Labels

area-testingauthor-verification-requestedIssues potentially verifiable by issue authorbugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from postertriage-neededNeeds assignment to the proper sub-teamverifiedVerification succeeded

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions