diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2018-07-17 21:27:46 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2018-07-26 10:36:11 -0700 |
commit | 4035958005f57bc617e3067e0b35c7409a32be33 (patch) | |
tree | 802dc51b2cfa36d44cce761f818976164efefd0c /tests | |
parent | 4bd5878ce01d86f9635f3e736cea0022a6e26b46 (diff) |
utilities: Add a decorator for asyncio tests
This decorator works to allow tests for pure asyncio coroutines to
operate synchronously.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/utilities.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/utilities.py b/tests/utilities.py index 2f5d2611..438cb798 100644 --- a/tests/utilities.py +++ b/tests/utilities.py @@ -16,6 +16,7 @@ """Helpers for unittests themselves.""" +import asyncio import functools import unittest @@ -186,3 +187,14 @@ def expected_failure(func): """ func.todo = 'expected failure' return func + + +def async_test(coro): + """Run an asyncrounous test synchronously.""" + + @functools.wraps(coro) + def _actual(*args, **kwargs): + loop = asyncio.get_event_loop() + return loop.run_until_complete(coro(*args, **kwargs)) + + return _actual |