def test_exit_stack_exception_propagate():
h1 = mock.MagicMock()
h2 = mock.MagicMock()
v1 = mock.MagicMock()
v2 = mock.MagicMock()
error = ValueError('FUUU')
with pytest.raises(ValueError) as exc:
with ExitStack() as stack:
v = stack.enter_context(AutoClose(h1, v=v1))
assert v is v1
v = stack.enter_context(AutoClose(h2, v=v2))
assert v is v2
raise error
assert exc.value is error
h2.close.assert_called_once_with(ValueError, error, mock.ANY)
h1.close.assert_called_once_with(ValueError, error, mock.ANY)
评论列表
文章目录