Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_asyncio fails when run under -O #68007

Closed
brettcannon opened this issue Mar 31, 2015 · 12 comments
Closed

test_asyncio fails when run under -O #68007

brettcannon opened this issue Mar 31, 2015 · 12 comments
Labels
3.11 only security fixes easy topic-asyncio

Comments

@brettcannon
Copy link
Member

BPO 23819
Nosy @gvanrossum, @brettcannon, @asvetlov, @serhiy-storchaka, @1st1, @miss-islington, @kumaraditya303
PRs
  • bpo-23819: asyncio: Replace AssertionError with proper excs #29894
  • bpo-23819: Fix asyncio tests on python optimized mode #30195
  • bpo-23819: Get rid of assert statements in test_asyncio #30212
  • [3.10] bpo-23819: Get rid of assert statements in test_asyncio (GH-30212) #30213
  • [3.9] bpo-23819: Fix asyncio tests on python optimized mode (GH-30195) #30265
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2022-01-09.07:42:51.750>
    created_at = <Date 2015-03-31.13:31:35.871>
    labels = ['easy', '3.11', 'expert-asyncio']
    title = 'test_asyncio fails when run under -O'
    updated_at = <Date 2022-01-09.07:42:51.749>
    user = 'https://github.com/brettcannon'

    bugs.python.org fields:

    activity = <Date 2022-01-09.07:42:51.749>
    actor = 'asvetlov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-09.07:42:51.750>
    closer = 'asvetlov'
    components = ['asyncio']
    creation = <Date 2015-03-31.13:31:35.871>
    creator = 'brett.cannon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 23819
    keywords = ['patch', 'easy']
    message_count = 12.0
    messages = ['239704', '239706', '355043', '407179', '407309', '407355', '407879', '408950', '408957', '409189', '409194', '410135']
    nosy_count = 7.0
    nosy_names = ['gvanrossum', 'brett.cannon', 'asvetlov', 'serhiy.storchaka', 'yselivanov', 'miss-islington', 'kumaraditya']
    pr_nums = ['29894', '30195', '30212', '30213', '30265']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue23819'
    versions = ['Python 3.11']

    @brettcannon
    Copy link
    Member Author

    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'

    @vstinner
    Copy link
    Member

    -O disables assertions, and asyncio has a ton of assertions. Some tests maybe rely on them? I guess that they are real bugs (assert must be replaced with a regular if+raise) in the middle of the failures.

    @vstinner
    Copy link
    Member

    This issue is still relevant 4 years later: many test_asyncio tests fail with python3 -O :-(

    @iritkatriel iritkatriel added the 3.11 only security fixes label Nov 27, 2021
    @gvanrossum
    Copy link
    Member

    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.)

    @gvanrossum
    Copy link
    Member

    I'd be happy to mentor someone who wants to tackle this.

    @kumaraditya303
    Copy link
    Contributor

    I would like to tackle this, I'll work on this from next week.

    @asvetlov
    Copy link
    Contributor

    asvetlov commented Dec 6, 2021

    New changeset 265918b by Kumar Aditya in branch 'main':
    bpo-23819: asyncio: Replace AssertionError with TypeError where it makes sense (GH-29894)
    265918b

    @serhiy-storchaka
    Copy link
    Member

    New changeset 6ca78af by Serhiy Storchaka in branch 'main':
    bpo-23819: Get rid of assert statements in test_asyncio (GH-30212)
    6ca78af

    @serhiy-storchaka
    Copy link
    Member

    New changeset 9594816 by Miss Islington (bot) in branch '3.10':
    bpo-23819: Get rid of assert statements in test_asyncio (GH-30212) (GH-30213)
    9594816

    @serhiy-storchaka
    Copy link
    Member

    New changeset a23ab7b by Kumar Aditya in branch 'main':
    bpo-23819: Fix asyncio tests on python optimized mode (GH-30195)
    a23ab7b

    @serhiy-storchaka
    Copy link
    Member

    New changeset 0722905 by Miss Islington (bot) in branch '3.9':
    [3.9] bpo-23819: Fix asyncio tests on python optimized mode (GH-30195) (GH-30265)
    0722905

    @asvetlov
    Copy link
    Contributor

    asvetlov commented Jan 9, 2022

    Is anything left to do?

    @asvetlov asvetlov closed this as completed Jan 9, 2022
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes easy topic-asyncio
    Projects
    None yet
    Development

    No branches or pull requests

    7 participants