diff options
author | Petter Strandmark <petter.strandmark@gmail.com> | 2020-12-03 08:46:03 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-12-14 20:46:18 +0100 |
commit | 772eca0b0219f63129282c3596fc210951433c13 (patch) | |
tree | 215f0dbc68598d82eb056ba316c0d42f7af8cb78 /tests/servers | |
parent | 28124e7bdf165689f92d667af1b77169ec75486c (diff) | |
download | django-772eca0b0219f63129282c3596fc210951433c13.tar.gz |
Fixed #32240 -- Made runserver suppress ConnectionAbortedError/ConnectionResetError errors.
See https://bugs.python.org/issue27682 and
https://github.com/python/cpython/pull/9713
Diffstat (limited to 'tests/servers')
-rw-r--r-- | tests/servers/test_basehttp.py | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/tests/servers/test_basehttp.py b/tests/servers/test_basehttp.py index 4c685b282f..b90e8565a6 100644 --- a/tests/servers/test_basehttp.py +++ b/tests/servers/test_basehttp.py @@ -113,15 +113,22 @@ class WSGIServerTestCase(SimpleTestCase): request = WSGIRequest(self.request_factory.get('/').environ) client_address = ('192.168.2.0', 8080) msg = f'- Broken pipe from {client_address}\n' - try: - server = WSGIServer(('localhost', 0), WSGIRequestHandler) - try: - raise BrokenPipeError() - except Exception: - with captured_stderr() as err: - with self.assertLogs('django.server', 'INFO') as cm: - server.handle_error(request, client_address) - self.assertEqual(err.getvalue(), '') - self.assertEqual(cm.records[0].getMessage(), msg) - finally: - server.server_close() + tests = [ + BrokenPipeError, + ConnectionAbortedError, + ConnectionResetError, + ] + for exception in tests: + with self.subTest(exception=exception): + try: + server = WSGIServer(('localhost', 0), WSGIRequestHandler) + try: + raise exception() + except Exception: + with captured_stderr() as err: + with self.assertLogs('django.server', 'INFO') as cm: + server.handle_error(request, client_address) + self.assertEqual(err.getvalue(), '') + self.assertEqual(cm.records[0].getMessage(), msg) + finally: + server.server_close() |