summaryrefslogtreecommitdiff
path: root/Lib/test/test_wsgiref.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_wsgiref.py')
-rw-r--r--Lib/test/test_wsgiref.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py
index 46f88a9443..42432bfbd2 100644
--- a/Lib/test/test_wsgiref.py
+++ b/Lib/test/test_wsgiref.py
@@ -806,6 +806,31 @@ class HandlerTests(TestCase):
self.assertFalse(stderr.getvalue())
+ def testDontResetInternalStateOnException(self):
+ class CustomException(ValueError):
+ pass
+
+ # We are raising CustomException here to trigger an exception
+ # during the execution of SimpleHandler.finish_response(), so
+ # we can easily test that the internal state of the handler is
+ # preserved in case of an exception.
+ class AbortingWriter:
+ def write(self, b):
+ raise CustomException
+
+ stderr = StringIO()
+ environ = {"SERVER_PROTOCOL": "HTTP/1.0"}
+ h = SimpleHandler(BytesIO(), AbortingWriter(), stderr, environ)
+ h.run(hello_app)
+
+ self.assertIn("CustomException", stderr.getvalue())
+
+ # Test that the internal state of the handler is preserved.
+ self.assertIsNotNone(h.result)
+ self.assertIsNotNone(h.headers)
+ self.assertIsNotNone(h.status)
+ self.assertIsNotNone(h.environ)
+
if __name__ == "__main__":
unittest.main()