From 4035958005f57bc617e3067e0b35c7409a32be33 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 17 Jul 2018 21:27:46 -0700 Subject: utilities: Add a decorator for asyncio tests This decorator works to allow tests for pure asyncio coroutines to operate synchronously. --- tests/utilities.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') 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 -- cgit v1.2.3