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.
This commit is contained in:
Mateusz Mandera 2024-10-27 03:05:02 +01:00 committed by Tim Abbott
parent eb31fdbe3c
commit d708a1bea5
1 changed files with 1 additions and 1 deletions

View File

@ -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)