我对python中基本的unittest方法的理解有分歧。给出以下测试文件:import unittest, sys
class TestStringMethods(unittest.TestCase):
def setUp(self):
self.mystring = "example string"
def tearDown(self):
del self.mystring
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())
def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
with self.assertRaises(TypeError):
s.split(2)
我的同事将这些文档解释为unittest的工作原理如下:1. set up self.mystring
2. run test_upper
3. run test_isupper
4. run test_split
5. tear down self.mystring
这是一个非常重要的区别,哪一个是正确的?在