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

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

问题描述

我有一个名为unittest的文件: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时出现错误:

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:“模块"对象没有属性"TestCase"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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