def test_fail(self): exc = ValueError() fun = unittest.mock.MagicMock() fun.return_value = None ec_future = asyncio.ensure_future(self.xmlstream.error_future()) features_future = self.xmlstream.features_future() self.xmlstream.on_closing.connect(fun) run_coroutine( self.xmlstream.run_test([], stimulus=XMLStreamMock.Fail(exc=exc))) self.assertTrue(ec_future.done()) self.assertIs(exc, ec_future.exception()) self.assertTrue(features_future.done()) self.assertIs(exc, features_future.exception()) fun.assert_called_once_with(exc) with self.assertRaises(ValueError) as ctx: self.xmlstream.reset() self.assertIs(exc, ctx.exception) with self.assertRaises(ValueError) as ctx: run_coroutine(self.xmlstream.starttls(object())) self.assertIs(exc, ctx.exception) with self.assertRaises(ValueError) as ctx: self.xmlstream.send_xso(object()) self.assertIs(exc, ctx.exception) with self.assertRaisesRegex(TypeError, "clear_exception"): run_coroutine(self.xmlstream.run_test([], clear_exception=True))