diff --git a/test/test_as_future.py b/test/test_as_future.py index 43cf0b6..2df3d83 100644 --- a/test/test_as_future.py +++ b/test/test_as_future.py @@ -30,7 +30,7 @@ import txaio from util import run_once -def test_as_future_immediate(): +def test_as_future_immediate(framework): ''' Returning an immediate value from as_future ''' @@ -59,7 +59,7 @@ def test_as_future_immediate(): assert calls[0] == ((1, 2, 3), dict(key='word')) -def test_as_future_immediate_none(): +def test_as_future_immediate_none(framework): ''' Returning None immediately from as_future ''' @@ -88,7 +88,7 @@ def test_as_future_immediate_none(): assert calls[0] == ((1, 2, 3), dict(key='word')) -def test_as_future_coroutine(): +def test_as_future_coroutine(framework): ''' call a coroutine (asyncio) ''' @@ -127,7 +127,7 @@ def test_as_future_coroutine(): assert calls[0] == ((1, 2, 3), dict(key='word')) -def test_as_future_exception(): +def test_as_future_exception(framework): ''' Raises an exception from as_future ''' @@ -157,7 +157,7 @@ def test_as_future_exception(): assert calls[0] == ((1, 2, 3), dict(key='word')) -def test_as_future_recursive(): +def test_as_future_recursive(framework): ''' Returns another Future from as_future ''' diff --git a/test/test_call_later.py b/test/test_call_later.py index 4edf9bb..f9b34f7 100644 --- a/test/test_call_later.py +++ b/test/test_call_later.py @@ -31,20 +31,23 @@ import txaio from txaio.testutil import replace_loop -def test_default_reactor(): +def test_default_reactor(framework_tx): """ run the code that defaults txaio.config.loop """ pytest.importorskip('twisted') assert txaio.config.loop is None - txaio.call_later(1, lambda: None) + try: + txaio.call_later(1, lambda: None) - from twisted.internet import reactor - assert txaio.config.loop is reactor + from twisted.internet import reactor + assert txaio.config.loop is reactor + finally: + txaio.config.loop = None -def test_explicit_reactor_future(): +def test_explicit_reactor_future(framework): """ If we set an event-loop, Futures + Tasks should use it. """ @@ -61,7 +64,7 @@ def test_explicit_reactor_future(): assert c[0] == 'call_soon' -def test_explicit_reactor_coroutine(): +def test_explicit_reactor_coroutine(framework): """ If we set an event-loop, Futures + Tasks should use it. """ @@ -83,7 +86,7 @@ def test_explicit_reactor_coroutine(): assert c[0] == 'call_soon' -def test_call_later(): +def test_call_later(framework_tx): ''' Wait for two Futures. ''' diff --git a/test/test_callback.py b/test/test_callback.py index 44c3299..16ba45c 100644 --- a/test/test_callback.py +++ b/test/test_callback.py @@ -29,7 +29,7 @@ import txaio from util import run_once -def test_default_resolve(): +def test_default_resolve(framework): f = txaio.create_future() results = [] @@ -44,7 +44,7 @@ def test_default_resolve(): assert results[0] is None -def test_callback(): +def test_callback(framework): f = txaio.create_future() results = [] @@ -59,7 +59,7 @@ def test_callback(): assert results[0] == "it worked" -def test_chained_callback(): +def test_chained_callback(framework): """ Chain two callbacks where the first one alters the value. """ @@ -84,7 +84,7 @@ def test_chained_callback(): assert calls[1] == "the deal pray I do not alter it futher" -def test_immediate_result(): +def test_immediate_result(framework): f = txaio.create_future_success("it worked") results = [] diff --git a/test/test_create.py b/test/test_create.py index c1e43f3..2cc078b 100644 --- a/test/test_create.py +++ b/test/test_create.py @@ -1,7 +1,7 @@ import txaio -def test_illegal_args(): +def test_illegal_args(framework): try: txaio.create_future(result=1, error=RuntimeError("foo")) assert False @@ -9,7 +9,7 @@ def test_illegal_args(): pass -def test_create_result(): +def test_create_result(framework): f = txaio.create_future(result='foo') if txaio.using_twisted: assert f.called @@ -17,7 +17,7 @@ def test_create_result(): assert f.done() -def test_create_error(): +def test_create_error(framework): f = txaio.create_future(error=RuntimeError("test")) if txaio.using_twisted: assert f.called diff --git a/test/test_errback.py b/test/test_errback.py index aa7cfe0..b4e4ed2 100644 --- a/test/test_errback.py +++ b/test/test_errback.py @@ -29,7 +29,7 @@ import txaio from util import run_once -def test_errback(): +def test_errback(framework): f = txaio.create_future() exception = RuntimeError("it failed") errors = [] @@ -58,7 +58,7 @@ def test_errback(): assert 'it failed' in str(errors[0]) -def test_errback_without_except(): +def test_errback_without_except(framework): ''' Create a failure without an except block ''' @@ -84,7 +84,7 @@ def test_errback_without_except(): assert 'it failed' in str(errors[0]) -def test_errback_plain_exception(): +def test_errback_plain_exception(framework): ''' reject a future with just an Exception ''' @@ -109,7 +109,7 @@ def test_errback_plain_exception(): assert 'it failed' in str(errors[0]) -def test_errback_illegal_args(): +def test_errback_illegal_args(framework): ''' non-Exception/Failures should be rejected ''' @@ -121,7 +121,7 @@ def test_errback_illegal_args(): pass -def test_errback_reject_no_args(): +def test_errback_reject_no_args(framework): """ txaio.reject() with no args """ @@ -151,7 +151,7 @@ def test_errback_reject_no_args(): assert 'it failed' in str(errors[0]) -def test_immediate_failure(): +def test_immediate_failure(framework): exception = RuntimeError("it failed") try: raise exception diff --git a/test/test_gather.py b/test/test_gather.py index 58aaecf..9d3f176 100644 --- a/test/test_gather.py +++ b/test/test_gather.py @@ -29,7 +29,7 @@ import txaio from util import await -def test_gather_two(): +def test_gather_two(framework_tx): ''' Wait for two Futures. ''' @@ -72,7 +72,7 @@ def test_gather_two(): assert calls[1] == (tuple(), dict()) -def test_gather_no_consume(): +def test_gather_no_consume(framework_tx): ''' consume_exceptions=False ''' diff --git a/test/test_imports.py b/test/test_imports.py index 30e748e..911ab89 100644 --- a/test/test_imports.py +++ b/test/test_imports.py @@ -1,7 +1,7 @@ import pytest -def test_use_twisted(): +def test_use_twisted(framework_tx): pytest.importorskip('twisted') import txaio @@ -10,7 +10,7 @@ def test_use_twisted(): assert not txaio.using_asyncio -def test_use_twisted_no_twisted(): +def test_use_twisted_no_twisted(framework_uninitialized): # make sure we DO NOT have Twisted installed try: import twisted # noqa @@ -26,20 +26,12 @@ def test_use_twisted_no_twisted(): pass assert not txaio.using_twisted - assert txaio.using_asyncio -def test_use_asyncio(): +def test_use_asyncio(framework_aio): pytest.importorskip('asyncio') - # note: in the py34-twisted environments we have both, so make - # sure we "put it back"... import txaio - tx = txaio.using_twisted - try: - txaio.use_asyncio() - assert txaio.using_asyncio - assert not txaio.using_twisted - finally: - if tx: - txaio.use_twisted() + txaio.use_asyncio() + assert txaio.using_asyncio + assert not txaio.using_twisted diff --git a/test/test_is_future.py b/test/test_is_future.py index c08eac3..c67c453 100644 --- a/test/test_is_future.py +++ b/test/test_is_future.py @@ -24,11 +24,10 @@ # ############################################################################### -import pytest import txaio -def test_is_future_generic(): +def test_is_future_generic(framework): ''' Returning an immediate value from as_future ''' @@ -37,14 +36,10 @@ def test_is_future_generic(): assert txaio.is_future(f) -def test_is_future_coroutine(): +def test_is_future_coroutine(framework_aio): ''' Returning an immediate value from as_future ''' - pytest.importorskip('asyncio') - if not txaio.using_asyncio: - pytest.skip() - from asyncio import coroutine @coroutine diff --git a/test/test_logging.py b/test/test_logging.py index e574910..ef708d4 100644 --- a/test/test_logging.py +++ b/test/test_logging.py @@ -46,8 +46,8 @@ class TestHandler(BytesIO): return self.getvalue().split(os.linesep.encode('ascii'))[:-1] -@pytest.fixture(scope='session') -def log_started(): +@pytest.fixture +def log_started(framework): """ Sets up the logging, which we can only do once per run. """ @@ -69,7 +69,7 @@ def handler(log_started): return log_started -def test_critical(handler): +def test_critical(handler, framework): logger = txaio.make_logger() # do something a little fancy, with attribute access etc. @@ -83,7 +83,7 @@ def test_critical(handler): assert handler.messages[0].endswith(b"hilarious wombat") -def test_info(handler): +def test_info(handler, framework): logger = txaio.make_logger() # do something a little fancy, with attribute access etc. @@ -97,13 +97,13 @@ def test_info(handler): assert handler.messages[0].endswith(b"hilarious elephant") -def test_bad_failures(handler): +def test_bad_failures(handler, framework): # just ensuring this doesn't explode txaio.failure_format_traceback("not a failure") txaio.failure_message("not a failure") -def test_debug_with_object(handler): +def test_debug_with_object(handler, framework): logger = txaio.make_logger() class Shape(object): @@ -120,7 +120,7 @@ def test_debug_with_object(handler): assert handler.messages[0].endswith(b"bar 4 bamboozle") -def test_log_noop_trace(handler): +def test_log_noop_trace(handler, framework): # trace should be a no-op, because we set the level to 'debug' in # the fixture logger = txaio.make_logger() @@ -130,14 +130,14 @@ def test_log_noop_trace(handler): assert len(handler.messages) == 0 -def test_double_start(handler): +def test_double_start(handler, framework): try: txaio.start_logging() except RuntimeError: assert False, "shouldn't get exception" -def test_invalid_level(): +def test_invalid_level(framework): try: txaio.start_logging(level='foo') assert False, "should get exception" @@ -145,7 +145,7 @@ def test_invalid_level(): assert 'Invalid log level' in str(e) -def test_class_descriptor(handler): +def test_class_descriptor(handler, framework): class Something(object): log = txaio.make_logger() @@ -159,7 +159,7 @@ def test_class_descriptor(handler): assert handler.messages[0].endswith(b"doing a thing") -def test_class_attribute(handler): +def test_class_attribute(handler, framework): class Something(object): def __init__(self): self.log = txaio.make_logger() @@ -174,7 +174,7 @@ def test_class_attribute(handler): assert handler.messages[0].endswith(b"doing a thing") -def test_log_converter(handler): +def test_log_converter(handler, framework): pytest.importorskip("twisted.logger") # this checks that we can convert a plain Twisted Logger calling # failure() into a traceback on our observers. @@ -195,7 +195,7 @@ def test_log_converter(handler): assert "Traceback" in output -def test_txlog_write_binary(handler): +def test_txlog_write_binary(handler, framework): """ Writing to a binary stream is supported. """ @@ -216,7 +216,7 @@ def test_txlog_write_binary(handler): assert b"hi: hello" in output -def test_txlog_write_text(handler): +def test_txlog_write_text(handler, framework_tx): """ Writing to a text stream is supported. """ @@ -237,7 +237,7 @@ def test_txlog_write_text(handler): assert u"hi: hello" in output -def test_aiolog_write_binary(handler): +def test_aiolog_write_binary(handler, framework_aio): """ Writing to a binary stream is supported. """ @@ -257,7 +257,7 @@ def test_aiolog_write_binary(handler): assert b"hi: hello" in output -def test_aiolog_write_text(handler): +def test_aiolog_write_text(handler, framework_aio): """ Writing to a text stream is supported. """