Skip to content

Commit

Permalink
test: update pytest-asyncio to 0.24.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Nov 6, 2024
1 parent 7a981cf commit fe225a6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion local-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ markers = [
]
junit_family = "xunit2"
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "session"

[tool.mypy]
ignore_missing_imports = true
Expand Down
11 changes: 7 additions & 4 deletions tests/async/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down Expand Up @@ -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


Expand All @@ -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":
Expand Down
12 changes: 2 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import asyncio
import inspect
import io
import json
import os
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
Expand All @@ -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"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit fe225a6

Please sign in to comment.