Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

ruff: Fix B017 `assertRaises(Exception):` should be considered evil.

Anders Kaseorg033d2615f661
diff --git a/zerver/tests/test_internet.py b/zerver/tests/test_internet.py
index 25cd92f5bda..3c1c8f6ea58 100644
--- a/zerver/tests/test_internet.py
+++ b/zerver/tests/test_internet.py
@@ -7,7 +7,10 @@ from zerver.lib.test_classes import ZulipTestCase
class ResponsesTest(ZulipTestCase):
def test_responses(self) -> None:
# With our test setup, accessing the internet should be blocked.
- with self.assertRaises(Exception):
+ with self.assertRaisesRegex(
+ Exception,
+ r"^Outgoing network requests are not allowed in the Zulip tests\.",
+ ):
result = requests.request("GET", "https://www.google.com")
# A test can invoke its own responses.RequestsMock context manager
diff --git a/zerver/tests/test_retention.py b/zerver/tests/test_retention.py
index 55166bb25d3..42629586d59 100644
--- a/zerver/tests/test_retention.py
+++ b/zerver/tests/test_retention.py
@@ -330,8 +330,10 @@ class TestArchiveMessagesGeneral(ArchiveMessagesTestingBase):
expired_usermsg_ids = self._get_usermessage_ids(expired_msg_ids)
# Insert an exception near the end of the archiving process of a chunk:
- with mock.patch("zerver.lib.retention.delete_messages", side_effect=Exception):
- with self.assertRaises(Exception):
+ with mock.patch(
+ "zerver.lib.retention.delete_messages", side_effect=Exception("delete_messages error")
+ ):
+ with self.assertRaisesRegex(Exception, r"^delete_messages error$"):
# Specify large chunk_size to ensure things happen in a single batch
archive_messages(chunk_size=1000)