如何生成嵌套的WITH语句?示例:
with patch.object(getattr("module1", "cls1"), "foo"):
with patch.object(getattr("module2", "cls2"), "foo"):
with patch.object(getattr("module3", "cls3"), "foo"):
# do something
如果我有一个需要放入嵌套的with
个语句中的项的列表,例如
list=[("module1", "cls1"), ("module2", "cls2"), ("module3", "cls3")]
个
我如何才能模拟上面的代码?