Python模块属性错误

时间:2017-07-11 19:11:30

标签: python-3.x python-unittest attributeerror

我知道这个话题已多次出现,但我完全陷入困境并需要帮助。请告诉我这里做错了什么以及如何解决它。提前谢谢。

# testcase1.py

import unittest
import sys


class Global:

    b = 0


class Util_Case_ID(unittest.TestCase):

    def setUp(self):
        sys.path.insert(0, 'C:/**/views')
        sys.path.insert(0, 'C:/**/app')
        sys.path.insert(0, 'C:/**/tests')

        from app.views.utility import method_a
        Global.b = len(method_a())

    def test1(self):
        self.assertEqual(Global.b, 11)

    def tearDown(self):
        sys.path.remove('C:/***/app/views')
        sys.path.remove('C:/***/app')
        sys.path.remove('C:/*/tests')

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

AttributeError:module' UnitTests'没有属性' testcase1'

Traceback如下:

Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\JetBrains\PyCharm Edu 3.5.1\helpers\pycharm\utrunner.py", line 167, in <module>
    all.addTests(testLoader.loadTestsFromTestClass(getattr(module, a[1])),
  File "C:\Users\*****\AppData\Roaming\JetBrains\PyCharm Edu 3.5.1\helpers\pycharm\nose_helper\loader.py", line 108, in loadTestsFromTestClass
    return self.suiteClass(ContextList(cases, context=cls))
  File "C:\Users\*****\AppData\Roaming\JetBrains\PyCharm Edu 3.5.1\helpers\pycharm\nose_helper\suite.py", line 253, in __call__
    return self.makeSuite(tests, context, **kw)
  File "C:\Users\*****\AppData\Roaming\JetBrains\PyCharm Edu 3.5.1\helpers\pycharm\nose_helper\suite.py", line 291, in makeSuite
    for ancestor in self.ancestry(context):
  File "C:\Users\******\AppData\Roaming\JetBrains\PyCharm Edu 3.5.1\helpers\pycharm\nose_helper\suite.py", line 269, in ancestry
    yield resolve_name('.'.join(ancestors))
  File "C:\Users\*****\AppData\Roaming\JetBrains\PyCharm Edu 3.5.1\helpers\pycharm\nose_helper\util.py", line 70, in resolve_name
    obj = getattr(obj, part)
AttributeError: module 'UnitTests' has no attribute 'testcase1'
Process finished with exit code 1

0 个答案:

没有答案