Description
Type: Bug
Behaviour
Expected vs. Actual
from utils import xyz
fails with ModuleNotFoundError when running a test in the Debugger. Simply running a test without the debugger works.
This is because the project's utils module is shadowed by the unittestadapter.utils module.
Notably, until yesterday debugging the same tests worked without problems and VSCode has not been updated since yesterday. The only thing I changed was moving my project folder to a different location. Moving it back to the original location did not resolve the issue
Steps to reproduce:
- Have a module named utils
- Import it from a test
- Run the test with the debugger
I've found somebody having the same problem on stackoverflow (https://stackoverflow.com/questions/77314758/vscode-python-unittest-discovery-fails-utils-is-not-a-package-sys-path-ord). In their case switching from unittest to pytest caused the issue to disapear. This did not help in my case.
Diagnostic data
- Python version (& distribution if applicable, e.g. Anaconda): 3.10.13
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
- Value of the
python.languageServer
setting: Default
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
ImportError: Failed to import test module: test_forecast_models
Traceback (most recent call last):
File "C:\Users\Kleindienst\AppData\Local\anaconda3\envs\prognos1123\lib\unittest\loader.py", line 154, in loadTestsFromName
module = __import__(module_name)
File "C:\Users\Kleindienst\Documents\GitProjects\tis-prognos-ai\src\PrognosAI.Python\tests\test_forecast_models.py", line 13, in <module>
from helpers import Measurement, PlanningArea
File "C:\Users\Kleindienst\Documents\GitProjects\tis-prognos-ai\src\PrognosAI.Python\helpers\__init__.py", line 1, in <module>
from helpers.influence_factors import InfluenceFactors, adjust_if_ranges
File "C:\Users\Kleindienst\Documents\GitProjects\tis-prognos-ai\src\PrognosAI.Python\helpers\influence_factors.py", line 17, in <module>
from helpers.planning_areas import PlanningArea
File "C:\Users\Kleindienst\Documents\GitProjects\tis-prognos-ai\src\PrognosAI.Python\helpers\planning_areas.py", line 12, in <module>
from db_utils import metadata
File "C:\Users\Kleindienst\Documents\GitProjects\tis-prognos-ai\src\PrognosAI.Python\db_utils\__init__.py", line 5, in <module>
from db_utils.db_utils import (
File "C:\Users\Kleindienst\Documents\GitProjects\tis-prognos-ai\src\PrognosAI.Python\db_utils\db_utils.py", line 17, in <module>
from tasklib import Task, TaskStatus
File "C:\Users\Kleindienst\Documents\GitProjects\tis-prognos-ai\src\PrognosAI.Python\tasklib\__init__.py", line 8, in <module>
from .notification import *
File "C:\Users\Kleindienst\Documents\GitProjects\tis-prognos-ai\src\PrognosAI.Python\tasklib\notification\__init__.py", line 4, in <module>
from .postgres_notification import PgPubSubNotificationFeature
File "C:\Users\Kleindienst\Documents\GitProjects\tis-prognos-ai\src\PrognosAI.Python\tasklib\notification\postgres_notification.py", line 9, in <module>
from utils.os_check import on_windows
ModuleNotFoundError: No module named 'utils.os_check'; 'utils' is not a package
----------------------------------------------------------------------
Ran 1 test in 0.003s
FAILED (errors=1)
(prognos1123) PS C:\Users\Kleindienst\Documents\GitProjects\tis-prognos-ai\src\PrognosAI.Python>
User Settings
languageServer: "Pylance"
testing
• pytestArgs: "<placeholder>"
• unittestArgs: "<placeholder>"
• unittestEnabled: true
Extension version: 2023.20.0
VS Code version: Code 1.83.1 (f1b07bd25dfad64b0167beb15359ae573aecd2cc, 2023-10-10T23:48:05.904Z)
OS version: Windows_NT x64 10.0.19045
Modes:
System Info
Item | Value |
---|---|
CPUs | 11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz (16 x 3600) |
GPU Status | 2d_canvas: enabled canvas_oop_rasterization: enabled_on 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) | 31.62GB (7.74GB free) |
Process Argv | --crash-reporter-id 59a9855f-53aa-4c85-9467-0b5e31a9f59b |
Screen Reader | no |
VM | 0% |
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscorecescf:30445987
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
pythonvs932:30410667
py29gd2263:30899288
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253
azure-dev_surveyone:30548225
2e4cg342:30602488
f6dab269:30613381
2i9eh265:30646982
showlangstatbar:30737416
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
welcomedialog:30887143
pythonnosmt12:30797651
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
dsvsc013:30795093
dsvsc014:30804076
dsvsc015:30845448
pythontestfixt:30902429
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
2e7ec940:30885897
pythontbext0:30879054
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
aa_t_chat:30882232