1616from typing import Any , AsyncGenerator , Awaitable , Callable , Dict , Generator , List
1717
1818import pytest
19+ from pytest_asyncio import is_async_test
1920
2021from 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
4041def 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" :
0 commit comments