Skip to content

Commit d0ac4c0

Browse files
authored
test: update pytest-asyncio to 0.24.0 (#2635)
1 parent 7a981cf commit d0ac4c0

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

local-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pixelmatch==0.3.0
1010
pre-commit==3.5.0
1111
pyOpenSSL==24.2.1
1212
pytest==8.3.3
13-
pytest-asyncio==0.21.2
13+
pytest-asyncio==0.24.0
1414
pytest-cov==6.0.0
1515
pytest-repeat==0.9.3
1616
pytest-timeout==2.3.1

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ markers = [
1515
]
1616
junit_family = "xunit2"
1717
asyncio_mode = "auto"
18+
asyncio_default_fixture_loop_scope = "session"
1819

1920
[tool.mypy]
2021
ignore_missing_imports = true

tests/async/conftest.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from typing import Any, AsyncGenerator, Awaitable, Callable, Dict, Generator, List
1717

1818
import pytest
19+
from pytest_asyncio import is_async_test
1920

2021
from playwright.async_api import (
2122
Browser,
@@ -38,8 +39,10 @@ def utils() -> Generator[Utils, None, None]:
3839

3940
# Will mark all the tests as async
4041
def pytest_collection_modifyitems(items: List[pytest.Item]) -> None:
41-
for item in items:
42-
item.add_marker(pytest.mark.asyncio)
42+
pytest_asyncio_tests = (item for item in items if is_async_test(item))
43+
session_scope_marker = pytest.mark.asyncio(loop_scope="session")
44+
for async_test in pytest_asyncio_tests:
45+
async_test.add_marker(session_scope_marker, append=False)
4346

4447

4548
@pytest.fixture(scope="session")
@@ -85,7 +88,7 @@ async def browser(
8588

8689

8790
@pytest.fixture(scope="session")
88-
async def browser_version(browser: Browser) -> str:
91+
def browser_version(browser: Browser) -> str:
8992
return browser.version
9093

9194

@@ -106,7 +109,7 @@ async def launch(**kwargs: Any) -> BrowserContext:
106109

107110

108111
@pytest.fixture(scope="session")
109-
async def default_same_site_cookie_value(browser_name: str, is_linux: bool) -> str:
112+
def default_same_site_cookie_value(browser_name: str, is_linux: bool) -> str:
110113
if browser_name == "chromium":
111114
return "Lax"
112115
if browser_name == "firefox":

tests/conftest.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import asyncio
1615
import inspect
1716
import io
1817
import json
1918
import os
2019
import subprocess
2120
import sys
2221
from pathlib import Path
23-
from typing import Any, AsyncGenerator, Callable, Dict, Generator, List, Optional, cast
22+
from typing import Any, Callable, Dict, Generator, List, Optional, cast
2423

2524
import pytest
2625
from PIL import Image
@@ -41,13 +40,6 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
4140
metafunc.parametrize("browser_name", browsers, scope="session")
4241

4342

44-
@pytest.fixture(scope="session")
45-
def event_loop() -> Generator[asyncio.AbstractEventLoop, None, None]:
46-
loop = asyncio.get_event_loop()
47-
yield loop
48-
loop.close()
49-
50-
5143
@pytest.fixture(scope="session")
5244
def assetdir() -> Path:
5345
return _dirname / "assets"
@@ -77,7 +69,7 @@ def https_server() -> Generator[Server, None, None]:
7769

7870

7971
@pytest.fixture(autouse=True, scope="session")
80-
async def start_server() -> AsyncGenerator[None, None]:
72+
def start_server() -> Generator[None, None, None]:
8173
test_server.start()
8274
yield
8375
test_server.stop()

0 commit comments

Comments
 (0)