Python单元测试类找不到self

时间:2014-11-18 05:44:20

标签: python unit-testing

我有以下用Python编写的单元测试用例。

import unittest
import json
from rules import RULES

class RulesTest(unittest.TestCase):

    def setup(self):
        self.rules = RULES()
        self.har_json = json.load(test.har)

    def test_get_total_request(self):
        length = self.rules.get_total_request(self.har_json)
        self.assertEqual(length, 484)


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

执行时它会给我错误。

Traceback (most recent call last):
File "rules_test.py", line 10, in <module>
class RulesTest(unittest.TestCase):
File "rules_test.py", line 18, in RulesTest
self.assertEqual(length, 484)
NameError: name 'self' is not defined

任何人都可以告诉我为什么python类无法找到自己。

0 个答案:

没有答案