Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
middleware: Pass unhandled API exceptions through to the test suite.
Anders Kaseorg345ed1d09db6
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.pyindex 6fb9a8423bc..0390210ccc2 100644--- a/zerver/lib/test_classes.py+++ b/zerver/lib/test_classes.py@@ -1631,7 +1631,7 @@ class WebhookTestCase(ZulipTestCase):complete_event_type is not Noneand all_event_types is not Noneand complete_event_type not in all_event_types- ):+ ): # nocoverageraise Exception(f"""Error: This test triggered a message using the event "{complete_event_type}", which was not properlydiff --git a/zerver/middleware.py b/zerver/middleware.pyindex f8284292c48..93c6f0e8519 100644--- a/zerver/middleware.py+++ b/zerver/middleware.py@@ -478,7 +478,7 @@ class JsonErrorHandler(MiddlewareMixin):if isinstance(exception, JsonableError):return json_response_from_error(exception)- if RequestNotes.get_notes(request).error_format == "JSON":+ if RequestNotes.get_notes(request).error_format == "JSON" and not settings.TEST_SUITE:capture_exception(exception)json_error_logger = logging.getLogger("zerver.middleware.json_error_handler")json_error_logger.error(traceback.format_exc(), extra=dict(request=request))diff --git a/zerver/tests/test_integrations_dev_panel.py b/zerver/tests/test_integrations_dev_panel.pyindex 7888f480c85..c63c3ae794c 100644--- a/zerver/tests/test_integrations_dev_panel.py+++ b/zerver/tests/test_integrations_dev_panel.py@@ -22,7 +22,7 @@ class TestIntegrationsDevPanel(ZulipTestCase):"custom_headers": "{}","is_json": "true",}- with self.assertLogs(level="ERROR") as logs:+ with self.assertLogs(level="ERROR") as logs, self.settings(TEST_SUITE=False):response = self.client_post(target_url, data)self.assertEqual(response.status_code, 500) # Since the response would be forwarded.diff --git a/zerver/tests/test_logging_handlers.py b/zerver/tests/test_logging_handlers.pyindex ab49474cbcd..7bceb6db46d 100644--- a/zerver/tests/test_logging_handlers.py+++ b/zerver/tests/test_logging_handlers.py@@ -81,7 +81,9 @@ class AdminNotifyHandlerTest(ZulipTestCase):"django.request", level="ERROR") as request_error_log, self.assertLogs("zerver.middleware.json_error_handler", level="ERROR"- ) as json_error_handler_log:+ ) as json_error_handler_log, self.settings(+ TEST_SUITE=False+ ):rate_limit_patch.side_effect = capture_and_throwresult = self.client_get("/json/users")self.assert_json_error(result, "Internal server error", status_code=500)diff --git a/zerver/webhooks/travis/tests.py b/zerver/webhooks/travis/tests.pyindex 0f62ffa294e..d21417de337 100644--- a/zerver/webhooks/travis/tests.py+++ b/zerver/webhooks/travis/tests.py@@ -114,25 +114,6 @@ Details: [changes](https://github.com/hl7-fhir/fhir-svn/compare/6dccb98bcfd9...6expect_noop=True,)- def test_travis_invalid_event(self) -> None:- payload = self.get_body("build")- payload = payload.replace("push", "invalid_event")- expected_error_messsage = """-Error: This test triggered a message using the event "invalid_event", which was not properly-registered via the @webhook_view(..., event_types=[...]). These registrations are important for Zulip-self-documenting the supported event types for this integration.--You can fix this by adding "invalid_event" to ALL_EVENT_TYPES for this webhook.-""".strip()- with self.assertLogs("django.request"):- with self.assertLogs("zerver.middleware.json_error_handler", level="ERROR") as m:- self.client_post(- self.url,- payload,- content_type="application/x-www-form-urlencoded",- )- self.assertIn(expected_error_messsage, m.output[0])-def test_travis_noop(self) -> None:expected_error_message = """While no message is expected given expect_noop=True,