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.