diff --git a/test/test_autoasync.py b/test/test_autoasync.py index 487ffa7..07acac5 100644 --- a/test/test_autoasync.py +++ b/test/test_autoasync.py @@ -113,23 +113,23 @@ def async_main(loop): def test_run_forever(context_loop): @asyncio.coroutine - def stop_loop_after_1_tenth_second(): - yield from asyncio.sleep(0.1) + def stop_loop_after(t): + yield from asyncio.sleep(t) context_loop.stop() retrieved_value = False @asyncio.coroutine - def set_value_after_half_tenth_second(): + def set_value_after(t): nonlocal retrieved_value - yield from asyncio.sleep(0.05) + yield from asyncio.sleep(t) retrieved_value = True @autoasync(forever=True) @asyncio.coroutine def async_main(): - asyncio.async(stop_loop_after_1_tenth_second()) - asyncio.async(set_value_after_half_tenth_second()) + asyncio.async(set_value_after(0.1)) + asyncio.async(stop_loop_after(0.2)) yield async_main() diff --git a/test/test_autocommand b/test/test_autocommand deleted file mode 100644 index e69de29..0000000 diff --git a/test/test_autocommand.py b/test/test_autocommand.py index 9ae2ef7..2425ddc 100644 --- a/test/test_autocommand.py +++ b/test/test_autocommand.py @@ -3,16 +3,15 @@ from unittest.mock import patch, sentinel from autocommand import autocommand -from test_markers import uses_async - -@pytest.fixture(scope='module') -def autocommand_module(): - return sys.modules['autocommand.autocommand'] +autocommand_module = sys.modules['autocommand.autocommand'] +uses_async = pytest.mark.skipif( + sys.version_info < (3, 4), + reason="async tests require python 3.4+") @pytest.yield_fixture -def patched_autoparse(autocommand_module): +def patched_autoparse(): with patch.object( autocommand_module, 'autoparse', @@ -21,7 +20,7 @@ def patched_autoparse(autocommand_module): @pytest.yield_fixture -def patched_autoasync(autocommand_module): +def patched_autoasync(): with patch.object( autocommand_module, 'autoasync', @@ -33,7 +32,7 @@ def patched_autoasync(autocommand_module): @pytest.yield_fixture -def patched_automain(autocommand_module): +def patched_automain(): with patch.object( autocommand_module, 'automain', diff --git a/test/test_automain.py b/test/test_automain.py index ae6194e..a476b60 100644 --- a/test/test_automain.py +++ b/test/test_automain.py @@ -27,18 +27,25 @@ def main(): def test_args(): - with pytest.raises(SystemExit) as exc_info: - @automain(True, args=[1, 2, 3]) - def main(a, b, c): + main_called = False + with pytest.raises(SystemExit): + @automain(True, args=[1, 2]) + def main(a, b): + nonlocal main_called + main_called = True assert a == 1 assert b == 2 - assert c == 3 + assert main_called -def test_kwargs(): - with pytest.raises(SystemExit) as exc_info: - @automain(True, kwargs={'a': 1, 'b': 2, 'c': 3}) - def main(a, b, c): +def test_args_and_kwargs(): + main_called = False + with pytest.raises(SystemExit): + @automain(True, args=[1], kwargs={'b': 2}) + def main(a, b): + nonlocal main_called + main_called = True assert a == 1 assert b == 2 - assert c == 3 + + assert main_called