summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-07-17 21:27:46 -0700
committerDylan Baker <dylan@pnwbakers.com>2018-07-26 10:36:11 -0700
commit4035958005f57bc617e3067e0b35c7409a32be33 (patch)
tree802dc51b2cfa36d44cce761f818976164efefd0c /tests
parent4bd5878ce01d86f9635f3e736cea0022a6e26b46 (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.py12
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