Sitelet https://github.com/python/cpython/issues/110774
Skip to content

Support setting the loop_factory in IsolatedAsyncioTestCase #110774

Description

@graingert

Proposal:

I want to be able to create utility subclasses of IsolatedAsyncioTestCase that use either uvloop or a specific event loop using the asyncio.Runner(..., loop_factory=...) kwarg, Ideally it would look something like:

Another advantage of setting loop_factory would allow use of IsolatedAsyncioTestCase without using def tearDownModule(): asyncio.set_event_loop_policy(None) because asyncio.Runner does not call asyncio.get_event_loop_policy() when called with a loop_factory

class DefaultIsolatedAsyncioTestCase:
    """
    Use the most efficient event loop regardless of what has been configured with asyncio.set_event_loop_policy
    does not require `def tearDownModule(): asyncio.set_event_loop_policy(None)`
    """
    loop_factory = asyncio.EventLoop

or

class UvloopIsolatedAsyncioTestCase:
    """
    runs tests on uvloop
    """
    loop_factory = uvloop.new_event_loop

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/support-setting-the-loop-factory-in-isolatedasynciotestcase/36027

Linked PRs

Activity

  1. added a commit that references this issue on Oct 31, 2023
  2. moved this from Todo to Done in asyncioon Oct 31, 2023
  3. added a commit that references this issue on Nov 3, 2023
  4. added a commit that references this issue on Feb 11, 2024
  5. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions