我希望能够使用unittest.TestCase
类的self.attr
,但是似乎在测试之间它不是持久化的:
import unittest
class TestNightlife(unittest.TestCase):
_my_param = 0
def test_a(self):
print 'test A = %d' % self._my_param
self._my_param = 1
def test_b(self):
print 'test B = %d' % self._my_param
self._my_param = 2
if __name__ == "__main__":
unittest.main()
这将产生以下输出:
test A = 0
test B = 0
< p >运行测试时,unittest.TestCase
实例是否会改变?为什么?
self
在测试之间发生了什么仍然是很有趣的问题。 - Jonathan Livni