aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar Akarys42 <[email protected]>2020-02-09 17:05:09 +0100
committerGravatar Akarys42 <[email protected]>2020-02-09 17:05:09 +0100
commitadf63e65a0b861cb02a6e8cc1e5b2c2c09e57726 (patch)
tree2faa92e60704b0518a0968b48361211e2e92f9bd /tests
parentUse actual functions instead of lambdas for bot.wait_for (diff)
Create an AsyncContextManagerMock mock for testing asynchronous context managers
It can be used to test aiohttp request functions, since they are async context managers
Diffstat (limited to 'tests')
-rw-r--r--tests/helpers.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py
index 5df796c23..6aee8623f 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -127,6 +127,18 @@ class AsyncMock(CustomMockMixin, unittest.mock.MagicMock):
return super().__call__(*args, **kwargs)
+class AsyncContextManagerMock(unittest.mock.MagicMock):
+ def __init__(self, return_value: Any):
+ super().__init__()
+ self._return_value = return_value
+
+ async def __aenter__(self):
+ return self._return_value
+
+ async def __aexit__(self, *args):
+ pass
+
+
class AsyncIteratorMock:
"""
A class to mock asynchronous iterators.