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.

tests: Remove `FORWARD_ADDRESS_CONFIG_FILE` created in test.

Lauryn Menardad2ca0e6685f
diff --git a/zerver/tests/test_email_log.py b/zerver/tests/test_email_log.py
index c4b2ac4d4b7..2509209496c 100644
--- a/zerver/tests/test_email_log.py
+++ b/zerver/tests/test_email_log.py
@@ -29,18 +29,22 @@ class EmailLogTest(ZulipTestCase):
self.assertEqual(m.output, [output_log for i in range(15)])
def test_forward_address_details(self) -> None:
- forward_address = "[email protected]"
- result = self.client_post("/emails/", {"forward_address": forward_address})
- self.assert_json_success(result)
-
- self.assertEqual(get_forward_address(), forward_address)
-
- with self.settings(EMAIL_BACKEND="zproject.email_backends.EmailLogBackEnd"), mock.patch(
- "zproject.email_backends.EmailLogBackEnd._do_send_messages", lambda *args: 1
- ):
- result = self.client_get("/emails/generate/")
- self.assertEqual(result.status_code, 302)
- self.assertIn("emails", result["Location"])
- result = self.client_get(result["Location"])
- self.assert_in_success_response([forward_address], result)
- os.remove(settings.FORWARD_ADDRESS_CONFIG_FILE)
+ try:
+ forward_address = "[email protected]"
+ result = self.client_post("/emails/", {"forward_address": forward_address})
+ self.assert_json_success(result)
+
+ self.assertEqual(get_forward_address(), forward_address)
+
+ with self.settings(EMAIL_BACKEND="zproject.email_backends.EmailLogBackEnd"), mock.patch(
+ "zproject.email_backends.EmailLogBackEnd._do_send_messages", lambda *args: 1
+ ):
+ result = self.client_get("/emails/generate/")
+ self.assertEqual(result.status_code, 302)
+ self.assertIn("emails", result["Location"])
+ result = self.client_get(result["Location"])
+ self.assert_in_success_response([forward_address], result)
+ # Remove this file, even if the test fails, so that it does
+ # not impact the state of the development environment.
+ finally:
+ os.remove(settings.FORWARD_ADDRESS_CONFIG_FILE)