AttributeError: 'module' 对象没有属性 'TestCase' [英] AttributeError: 'module' object has no attribute 'TestCase'

查看:34
本文介绍了AttributeError: 'module' 对象没有属性 'TestCase'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 test.py 的单元测试文件

I have file with unittest named: test.py

我的代码:

import unittest

class Test(unittest.TestCase):

    def myTest(self):
        a = 1
        self.assertEqual(a, 1)


if __name__ == '__main__':
    unittest.main()

当我按 F5 时,出现错误:

When I press F5, I get an error:

Traceback (most recent call last):
  File "/home/mariusz/Pulpit/test.py", line 1, in <module>
    import unittest
  File "/home/mariusz/Pulpit/unittest.py", line 3, in <module>
AttributeError: 'module' object has no attribute 'TestCase'

推荐答案

您有一个名为 unittest.py 的本地文件正在被导入:

You have a local file named unittest.py that is being imported instead:

/home/mariusz/Pulpit/unittest.py

重命名该文件或将其完全删除.确保删除同一文件夹中的所有相应 unittest.pyc 文件(如果存在).

Rename that file or remove it altogether. Make sure you remove any corresponding unittest.pyc file in the same folder if it is there.

该文件掩盖了标准库包.

The file is masking the standard library package.

这篇关于AttributeError: 'module' 对象没有属性 'TestCase'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆