我想在参数中使用python unittest setUpClass和tearDownClass方法。更具体地说,这就是我现在正在做的事情:
import unittest2 as unittest
cache = VCache(arg1, arg2, arg3)
class Validation(unittest.TestCase):
''' Unit test class with a local cache to avoid intensive network traffic. '''
@classmethod
def setUpClass(cls):
''' Copy all required data locally. '''
super(Validation, cls).setUpClass()
cache.setUp()
@classmethod
def tearDownClass(cls):
''' Remove the cache. '''
super(Validation, cls).tearDownClass()
cache.tearDown()
它有效但现在我想将缓存管理包装在Validation的子类中,以避免每次使用全局变量并编写setUpClass和tearDownClass。
这当然不起作用,因为setUpClass()和tearDownClass()不接受参数。任何解决方案?