From fe225a6437f7e305e81e2a717ceecd1225f7cafa Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 7 Nov 2024 00:45:04 +0100 Subject: [PATCH] test: update pytest-asyncio to 0.24.0 --- local-requirements.txt | 2 +- pyproject.toml | 1 + tests/async/conftest.py | 11 +++++++---- tests/conftest.py | 12 ++---------- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/local-requirements.txt b/local-requirements.txt index 3be80758b..4f7771e58 100644 --- a/local-requirements.txt +++ b/local-requirements.txt @@ -10,7 +10,7 @@ pixelmatch==0.3.0 pre-commit==3.5.0 pyOpenSSL==24.2.1 pytest==8.3.3 -pytest-asyncio==0.21.2 +pytest-asyncio==0.24.0 pytest-cov==6.0.0 pytest-repeat==0.9.3 pytest-timeout==2.3.1 diff --git a/pyproject.toml b/pyproject.toml index e65384134..ebf205069 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ markers = [ ] junit_family = "xunit2" asyncio_mode = "auto" +asyncio_default_fixture_loop_scope = "session" [tool.mypy] ignore_missing_imports = true diff --git a/tests/async/conftest.py b/tests/async/conftest.py index 268c8a433..c568067e5 100644 --- a/tests/async/conftest.py +++ b/tests/async/conftest.py @@ -16,6 +16,7 @@ from typing import Any, AsyncGenerator, Awaitable, Callable, Dict, Generator, List import pytest +from pytest_asyncio import is_async_test from playwright.async_api import ( Browser, @@ -38,8 +39,10 @@ def utils() -> Generator[Utils, None, None]: # Will mark all the tests as async def pytest_collection_modifyitems(items: List[pytest.Item]) -> None: - for item in items: - item.add_marker(pytest.mark.asyncio) + pytest_asyncio_tests = (item for item in items if is_async_test(item)) + session_scope_marker = pytest.mark.asyncio(loop_scope="session") + for async_test in pytest_asyncio_tests: + async_test.add_marker(session_scope_marker, append=False) @pytest.fixture(scope="session") @@ -85,7 +88,7 @@ async def browser( @pytest.fixture(scope="session") -async def browser_version(browser: Browser) -> str: +def browser_version(browser: Browser) -> str: return browser.version @@ -106,7 +109,7 @@ async def launch(**kwargs: Any) -> BrowserContext: @pytest.fixture(scope="session") -async def default_same_site_cookie_value(browser_name: str, is_linux: bool) -> str: +def default_same_site_cookie_value(browser_name: str, is_linux: bool) -> str: if browser_name == "chromium": return "Lax" if browser_name == "firefox": diff --git a/tests/conftest.py b/tests/conftest.py index 770bd9c30..968f10b2b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import asyncio import inspect import io import json @@ -20,7 +19,7 @@ import subprocess import sys from pathlib import Path -from typing import Any, AsyncGenerator, Callable, Dict, Generator, List, Optional, cast +from typing import Any, Callable, Dict, Generator, List, Optional, cast import pytest from PIL import Image @@ -41,13 +40,6 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None: metafunc.parametrize("browser_name", browsers, scope="session") -@pytest.fixture(scope="session") -def event_loop() -> Generator[asyncio.AbstractEventLoop, None, None]: - loop = asyncio.get_event_loop() - yield loop - loop.close() - - @pytest.fixture(scope="session") def assetdir() -> Path: return _dirname / "assets" @@ -77,7 +69,7 @@ def https_server() -> Generator[Server, None, None]: @pytest.fixture(autouse=True, scope="session") -async def start_server() -> AsyncGenerator[None, None]: +def start_server() -> Generator[None, None, None]: test_server.start() yield test_server.stop()