diff options
| author | 2019-09-23 16:16:10 +0200 | |
|---|---|---|
| committer | 2019-09-23 16:16:10 +0200 | |
| commit | f4f3b2a15ecdce5291ef2d2d98b0af6d77fbc228 (patch) | |
| tree | 250036c9d5162c6ee62d1a7bd6c999a03a2caad5 /tests/helpers.py | |
| parent | Change log.error to log.exception (diff) | |
| parent | Merge branch 'master' of https://github.com/python-discord/bot into python-di... (diff) | |
Merge branch 'python-discord-master'
Diffstat (limited to 'tests/helpers.py')
| -rw-r--r-- | tests/helpers.py | 29 |
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 |