unittest in Python
以下程序:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import unittest class my_class(unittest.TestCase): def setUp(self): print"In Setup" self.x=100 self.y=200 def test_case1(self): print"-------------" print"test case1" print self.x print"-------------" def test_case2(self): print"-------------" print"test case2" print self.y print"-------------" def tearDown(self): print"In Tear Down" print" " print" " if __name__ =="__main__": unittest.main() |
给出输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | >>> ================================ RESTART ================================ >>> In Setup ------------- test case1 100 ------------- In Tear Down .In Setup ------------- test case2 200 ------------- In Tear Down . ---------------------------------------------------------------------- Ran 2 tests in 0.113s OK >>> >>> |
号
问题:
"EDOCX1"〔0〕的意思是什么?
为什么我们为
在哪里创建
双下划线的前缀和后缀表示:
__double_leading_and_trailing_underscore__ :"magic" objects or attributes that live in user-controlled namespaces. E.g.__init__ ,__import__ or__file__ . Never invent such names; only use them as documented.
号
它来自于PEP8风格指南——这是一个非常有用的阅读和内化资源。
最后,当您的