From 0287a09cbed275eb0dc803c369c6cc88e1a004a5 Mon Sep 17 00:00:00 2001 From: "Mathias L. Baumann" Date: Thu, 26 Sep 2024 17:08:47 +0200 Subject: [PATCH] Update event_loop to explicitly set scope session As recommended by the deprecation warning Signed-off-by: Mathias L. Baumann --- pyproject.toml | 1 + tests/test_mananging_actor.py | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 280956e..d4f0d65 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -165,6 +165,7 @@ disable = [ [tool.pytest.ini_options] testpaths = ["tests", "src"] asyncio_mode = "auto" +asyncio_default_fixture_loop_scope = "function" required_plugins = ["pytest-asyncio", "pytest-mock"] [tool.mypy] diff --git a/tests/test_mananging_actor.py b/tests/test_mananging_actor.py index bab8361..100e2a7 100644 --- a/tests/test_mananging_actor.py +++ b/tests/test_mananging_actor.py @@ -9,7 +9,6 @@ from typing import AsyncIterator, Iterator import async_solipsism -import pytest import time_machine from frequenz.channels import Broadcast, Receiver, Sender from frequenz.client.dispatch.test.generator import DispatchGenerator @@ -20,11 +19,12 @@ from frequenz.dispatch import Dispatch, DispatchManagingActor, DispatchUpdate -# This method replaces the event loop for all tests in the file. -@pytest.fixture +@fixture def event_loop_policy() -> async_solipsism.EventLoopPolicy: - """Return an event loop policy that uses the async solipsism event loop.""" - return async_solipsism.EventLoopPolicy() + """Set the event loop policy to use async_solipsism.""" + policy = async_solipsism.EventLoopPolicy() + asyncio.set_event_loop_policy(policy) + return policy @fixture