Skip to content

Remove event_loop fixture #1106

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

Merged
merged 10 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1106.removed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The deprecated *event_loop* fixture.
5 changes: 0 additions & 5 deletions docs/reference/fixtures/event_loop_example.py

This file was deleted.

27 changes: 0 additions & 27 deletions docs/reference/fixtures/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,6 @@
Fixtures
========

event_loop
==========
*This fixture is deprecated.*

*If you want to request an asyncio event loop with a scope other than function
scope, use the "loop_scope" argument to* :ref:`reference/markers/asyncio` *when marking the tests.
If you want to return different types of event loops, use the* :ref:`reference/fixtures/event_loop_policy`
*fixture.*

Creates a new asyncio event loop based on the current event loop policy. The new loop
is available as the return value of this fixture for synchronous functions, or via `asyncio.get_running_loop <https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_running_loop>`__ for asynchronous functions.
The event loop is closed when the fixture scope ends.
The fixture scope defaults to ``function`` scope.

.. include:: event_loop_example.py
:code: python

Note that, when using the ``event_loop`` fixture, you need to interact with the event loop using methods like ``event_loop.run_until_complete``. If you want to *await* code inside your test function, you need to write a coroutine and use it as a test function. The :ref:`asyncio <reference/markers/asyncio>` marker
is used to mark coroutines that should be treated as test functions.

If you need to change the type of the event loop, prefer setting a custom event loop policy over redefining the ``event_loop`` fixture.

If the ``pytest.mark.asyncio`` decorator is applied to a test function, the ``event_loop``
fixture will be requested automatically by the test function.

.. _reference/fixtures/event_loop_policy:

event_loop_policy
=================
Returns the event loop policy used to create asyncio event loops.
Expand Down
Loading
Loading