diff options
author | Sean Quah <8349537+squahtx@users.noreply.github.com> | 2022-04-27 14:58:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-27 14:58:26 +0100 |
commit | 78b99de7c206b106340e12cdee0af9aa246bd5ad (patch) | |
tree | 7eb94bb066b8ed0b23fa160056b5e9bcdb29dd8e /tests/handlers/test_user_directory.py | |
parent | Add a module API to allow modules to edit push rule actions (#12406) (diff) | |
download | synapse-78b99de7c206b106340e12cdee0af9aa246bd5ad.tar.xz |
Prefer `make_awaitable` over `defer.succeed` in tests (#12505)
When configuring the return values of mocks, prefer awaitables from `make_awaitable` over `defer.succeed`. `Deferred`s are only awaitable once, so it is inappropriate for a mock to return the same `Deferred` multiple times. Also update `run_in_background` to support functions that return arbitrary awaitables. Signed-off-by: Sean Quah <seanq@element.io>
Diffstat (limited to 'tests/handlers/test_user_directory.py')
-rw-r--r-- | tests/handlers/test_user_directory.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/tests/handlers/test_user_directory.py b/tests/handlers/test_user_directory.py index c6e501c7be..96e2e3039b 100644 --- a/tests/handlers/test_user_directory.py +++ b/tests/handlers/test_user_directory.py @@ -15,7 +15,6 @@ from typing import Tuple from unittest.mock import Mock, patch from urllib.parse import quote -from twisted.internet import defer from twisted.test.proto_helpers import MemoryReactor import synapse.rest.admin @@ -30,6 +29,7 @@ from synapse.util import Clock from tests import unittest from tests.storage.test_user_directory import GetUserDirectoryTables +from tests.test_utils import make_awaitable from tests.test_utils.event_injection import inject_member_event from tests.unittest import override_config @@ -439,7 +439,7 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase): ) ) - mock_remove_from_user_dir = Mock(return_value=defer.succeed(None)) + mock_remove_from_user_dir = Mock(return_value=make_awaitable(None)) with patch.object( self.store, "remove_from_user_dir", mock_remove_from_user_dir ): @@ -454,7 +454,7 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase): self.store.register_user(user_id=r_user_id, password_hash=None) ) - mock_remove_from_user_dir = Mock(return_value=defer.succeed(None)) + mock_remove_from_user_dir = Mock(return_value=make_awaitable(None)) with patch.object( self.store, "remove_from_user_dir", mock_remove_from_user_dir ): |