我想在TestCase.setUpClass()
方法中为修补对象设置副作用,以便副作用将在整个测试中持续存在,而不必通过setUp()
.
如何访问 中的补丁@classmethod
?
@patch('my_module.auxiliary_module', autospec=True)
class TestMyModule(TestCase):
@classmethod
def setUpClass(cls):
# how can I access the patch here to set a side-effect?
def test_a(self, mock_auxiliary_module):
# here the patch is accessible
我想做的一个例子setUpClass()
:
mock_auxiliary_module.some_func.side_effect = lambda x: {'a': 2, 'b': 5}[x]