aboutsummaryrefslogtreecommitdiffstats
path: root/tests/helpers.py
diff options
context:
space:
mode:
authorGravatar Johannes Christ <[email protected]>2019-09-15 16:04:54 +0200
committerGravatar scragly <[email protected]>2019-09-18 01:13:48 +1000
commitad711f04a789811c1aade6b49639474c592c044c (patch)
treefc12ac0840ac69ce69cf5bea205a8ed9dc054bcd /tests/helpers.py
parentValidate configuration against typehints, remove old keys, renam… (#425) (diff)
Add basic tests for `bot.api`.
Diffstat (limited to 'tests/helpers.py')
-rw-r--r--tests/helpers.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/helpers.py b/tests/helpers.py
index 57c6fcc1a..f8fbb5e60 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -1,10 +1,30 @@
+import asyncio
+import functools
+
from unittest.mock import MagicMock
-__all__ = ('AsyncMock',)
+__all__ = ('AsyncMock', 'async_test')
# TODO: Remove me on 3.8
class AsyncMock(MagicMock):
async def __call__(self, *args, **kwargs):
return super(AsyncMock, self).__call__(*args, **kwargs)
+
+
+def async_test(wrapped):
+ """
+ Run a test case via asyncio.
+
+ Example:
+
+ >>> @async_test
+ ... async def lemon_wins():
+ ... assert True
+ """
+
+ @functools.wraps(wrapped)
+ def wrapper(*args, **kwargs):
+ return asyncio.run(wrapped(*args, **kwargs))
+ return wrapper