From d708a1bea5adf5c44e338e9546c93eef5e9176aa Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Sun, 27 Oct 2024 03:05:02 +0100 Subject: [PATCH] tests: Fix order of mock.patch in use_s3_backend. This is a somewhat hacky and fragile fix. Due to the order in which imports seem to happen, the original ordering breaks RealmImportExportTest: if one of the `use_s3_backend` tests runs before test_import_realm, the latter will fail while processing thumbnailing, as S3UploadBackend ends up leaking and zerver.worker.thumbnail.upload_backend is still set to S3. By making that mock.patch the first one that gets entered, and thus the last one to get cleaned up, we fix the leak and upload_backend is set back to LocalUploadBackend as it should. --- zerver/lib/test_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py index d5b5f375a5..b17169b9f6 100644 --- a/zerver/lib/test_helpers.py +++ b/zerver/lib/test_helpers.py @@ -603,8 +603,8 @@ def use_s3_backend(method: Callable[P, None]) -> Callable[P, None]: def new_method(*args: P.args, **kwargs: P.kwargs) -> None: backend = S3UploadBackend() with ( - mock.patch("zerver.lib.upload.upload_backend", backend), mock.patch("zerver.worker.thumbnail.upload_backend", backend), + mock.patch("zerver.lib.upload.upload_backend", backend), mock.patch("zerver.views.tusd.upload_backend", backend), ): return method(*args, **kwargs)