Issue 23819: test_asyncio fails when run under -O (original) (raw)

Ton of failures along the lines of:

====================================================================== ERROR: test_ctor (test.test_asyncio.test_unix_events.UnixReadPipeTransportTests)

Traceback (most recent call last): File "/Users/bcannon/Repositories/cpython/default/Lib/test/test_asyncio/test_unix_events.py", line 329, in setUp self.loop = self.new_test_loop() File "/Users/bcannon/Repositories/cpython/default/Lib/asyncio/test_utils.py", line 413, in new_test_loop self.set_event_loop(loop) File "/Users/bcannon/Repositories/cpython/default/Lib/asyncio/test_utils.py", line 407, in set_event_loop events.set_event_loop(None) File "/Users/bcannon/Repositories/cpython/default/Lib/asyncio/events.py", line 581, in set_event_loop get_event_loop_policy().set_event_loop(loop) AttributeError: 'object' object has no attribute 'set_event_loop'

I'm sure there's more to it, but I found at least this failure:

~/cpython$ ./python.exe -O -m test test_asyncio -m test_set_event_loop Raised RLIMIT_NOFILE: 256 -> 1024 0:00:00 load avg: 2.02 Run tests sequentially 0:00:00 load avg: 2.02 [1/1] test_asyncio test test_asyncio failed -- Traceback (most recent call last): File "/Users/guido/cpython/Lib/test/test_asyncio/test_events.py", line 2595, in test_set_event_loop self.assertRaises(AssertionError, policy.set_event_loop, object()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError: AssertionError not raised by set_event_loop

test_asyncio failed (1 failure)

== Tests result: FAILURE ==

1 test failed: test_asyncio

Total duration: 134 ms Tests result: FAILURE

Also this one:

~/cpython$ ./python.exe -O -m test test_asyncio -m test_create_datagram_endpoint_addr_error 0:00:00 load avg: 2.19 Run tests sequentially 0:00:00 load avg: 2.19 [1/1] test_asyncio test test_asyncio failed -- Traceback (most recent call last): File "/Users/guido/cpython/Lib/test/test_asyncio/test_base_events.py", line 1593, in test_create_datagram_endpoint_addr_error self.assertRaises( ^^^^^^^^^^^^^^^^^^ File "/Users/guido/cpython/Lib/unittest/case.py", line 734, in assertRaises return context.handle('assertRaises', args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/guido/cpython/Lib/unittest/case.py", line 218, in handle callable_obj(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/guido/cpython/Lib/asyncio/base_events.py", line 637, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/Users/guido/cpython/Lib/asyncio/base_events.py", line 1287, in create_datagram_endpoint infos = await self._ensure_resolved( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/guido/cpython/Lib/asyncio/base_events.py", line 1369, in _ensure_resolved info = _ipaddr_info(host, port, family, type, proto, *address[2:]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: _ipaddr_info() takes from 5 to 7 positional arguments but 12 were given

test_asyncio failed (1 error)

== Tests result: FAILURE ==

1 test failed: test_asyncio

Total duration: 165 ms Tests result: FAILURE

I think calling assertRaises(AssertionError, ...) is definitely an anti-pattern. We can't remove all assertions from the asyncio library, but I think the ones that are explicitly checked for by the tests should go, at least. (Probably replaced with TypeError or ValueError in most cases.)