From 536bc3113ebafebc2bfd0bf814622b2564e51db3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 23:02:12 +0000 Subject: [PATCH 1/2] Bump pytest-asyncio from 0.21.2 to 0.25.0 Bumps [pytest-asyncio](https://github.com/pytest-dev/pytest-asyncio) from 0.21.2 to 0.25.0. - [Release notes](https://github.com/pytest-dev/pytest-asyncio/releases) - [Commits](https://github.com/pytest-dev/pytest-asyncio/compare/v0.21.2...v0.25.0) --- updated-dependencies: - dependency-name: pytest-asyncio dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements-unit-tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-unit-tests.txt b/requirements-unit-tests.txt index 654bc9e9fdb..55699ce853a 100644 --- a/requirements-unit-tests.txt +++ b/requirements-unit-tests.txt @@ -7,7 +7,7 @@ build pytest==8.3.4 # needed because pytest doesn't come with native support for coroutines as tests -pytest-asyncio==0.21.2 +pytest-asyncio==0.25.0 # xdist runs tests in parallel pytest-xdist==3.6.1 From 6ddfeee8c4e317bb30356448da5fda8fdf607cbf Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sat, 14 Dec 2024 22:28:26 +0100 Subject: [PATCH 2/2] Don't work locally yet, but let's see how well it works online --- pyproject.toml | 1 + tests/conftest.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 58752295610..9a9b43ba154 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -181,6 +181,7 @@ markers = [ "req", ] asyncio_mode = "auto" +asyncio_default_fixture_loop_scope = "session" log_format = "%(funcName)s - Line %(lineno)d - %(message)s" # log_level = "DEBUG" # uncomment to see DEBUG logs diff --git a/tests/conftest.py b/tests/conftest.py index 70a19009624..a605a40de27 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -24,6 +24,7 @@ from uuid import uuid4 import pytest +from pytest_asyncio import is_async_test from telegram import ( CallbackQuery, @@ -77,7 +78,12 @@ def no_rerun_after_xfail_or_flood(error, name, test: pytest.Function, plugin): def pytest_collection_modifyitems(items: list[pytest.Item]): """Here we add a flaky marker to all request making tests and a (no_)req marker to the rest.""" + pytest_asyncio_session_scope_marker = pytest.mark.asyncio(loop_scope="session") + for item in items: # items are the test methods + if is_async_test(item): + item.add_marker(pytest_asyncio_session_scope_marker) + parent = item.parent # Get the parent of the item (class, or module if defined outside) if parent is None: # should never happen, but just in case return @@ -137,9 +143,10 @@ def event_loop(request): # ever since ProactorEventLoop became the default in Win 3.8+, the app crashes after the loop # is closed. Hence, we use SelectorEventLoop on Windows to avoid this. See # https://github.com/python/cpython/issues/83413, https://github.com/encode/httpx/issues/914 - if sys.platform.startswith("win"): - asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) - return asyncio.get_event_loop_policy().new_event_loop() + # if sys.platform.startswith("win"): + # asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) + # return asyncio.get_event_loop_policy().new_event_loop() + return asyncio.get_event_loop() # loop.close() # instead of closing here, do that at the every end of the test session