aboutsummaryrefslogtreecommitdiffstats
path: root/tests/helpers.py
diff options
context:
space:
mode:
authorGravatar sco1 <[email protected]>2019-09-18 14:00:57 -0700
committerGravatar sco1 <[email protected]>2019-09-18 14:10:06 -0700
commit2ac0c6df978f20a488b3eb026753c8a972cb2554 (patch)
tree43fc70b14b517139dea5324e762ba92a9e211e28 /tests/helpers.py
parentDocstring linting chunk 7 (diff)
parentMerge pull request #436 from python-discord/enhance-offtopicnames-search (diff)
Merge branch 'master' into flake8-plugins
Diffstat (limited to 'tests/helpers.py')
-rw-r--r--tests/helpers.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py
new file mode 100644
index 000000000..2908294f7
--- /dev/null
+++ b/tests/helpers.py
@@ -0,0 +1,29 @@
+import asyncio
+import functools
+from unittest.mock import MagicMock
+
+
+__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