Skip to main content
 首页 » 编程设计

Python 'cannot import name ' TestCase'' 导入unittest时

2025年01月19日8softidea

每当我尝试:

import unittest 

我收到以下错误:

 Traceback (most recent call last): 
  File "wackyTesting.py", line 1, in <module> 
    import unittest 
  File "C:\.....\Python\Python36\lib\unittest\__init__.py", line 59, in <module> 
    from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf, 
ImportError: cannot import name 'TestCase' 

无论代码在哪里运行,都会发生这种情况,根目录中没有任何内容可能导致冲突。我试过重新安装 unittest 但它没有帮助。直到最近它都运行良好。有什么想法吗?

请您参考如下方法:

好吧,我刚刚完全卸载 python 并重新安装。没有什么比将其关闭再打开更合适的了。这似乎已经做到了,也许有更优雅的解决方案,但现在必须这样做。