1
我想在TestCase.setUpClass()
方法中为修补对象设置一个副作用,以便在整个测试中持续存在副作用,而不必通过setUp()
对每个测试进行设置。访问@classmethod中的修补对象
如何访问@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]
你想从补丁对象中检索什么样的信息?无论是类数据还是实例数据? –
我也无法访问'setUp()'中的修补对象!
我想无论如何解决上面的问题也将解决'setUp()'案例 – Jonathan
@ AlexG.P。看到我上面的编辑 - 我想设置一个副作用,而不是从修补的对象中检索任何东西 – Jonathan