【发布时间】:2018-07-16 14:17:17
【问题描述】:
属于同一个TestCase成员的测试方法会相互影响吗?
在 python unittest 中,我试图理解,如果我在测试方法中更改变量,变量是否会在其他测试方法中更改。还是每个方法都运行 setUp 和 tearDown 方法,然后为每个方法重新设置变量?
我是说
AsdfTestCase(unittest.TestCase):
def setUp(self):
self.dict = {
'str': 'asdf',
'int': 10
}
def tearDown(self):
del self.dict
def test_asdf_1(self):
self.dict['str'] = 'test string'
def test_asdf_2(self):
print(self.dict)
所以我在问 test_asdf_2() 将打印哪个输出 'asdf' 或 'test_string'
【问题讨论】: