17
17
18
18
import pytest
19
19
20
+ @pytest .fixture (autouse = True )
21
+ def _set_default_ini_file (testdir : pytest .Testdir ) -> None :
22
+ testdir .makeconftest (
23
+ """
24
+ import pytest
25
+
26
+ from pytest_asyncio import is_async_test
27
+
28
+ def pytest_collection_modifyitems(items):
29
+ pytest_asyncio_tests = (item for item in items if is_async_test(item))
30
+ session_scope_marker = pytest.mark.asyncio(loop_scope="session")
31
+ for async_test in pytest_asyncio_tests:
32
+ async_test.add_marker(session_scope_marker, append=False)
33
+ """
34
+ )
35
+
36
+ def makeconftest (testdir : pytest .Testdir , content : str ) -> None :
37
+ lines = content .split ("\n " )
38
+ spaces = [len (line ) - len (line .lstrip ()) for line in lines if line .strip ()]
39
+ min_spaces = min (spaces ) if spaces else 0
40
+ lines = [line [min_spaces :] for line in lines ]
41
+
42
+ testdir .makeconftest (
43
+ testdir .tmpdir .join ("conftest.py" ).read_text ("utf8" )+ "\n " + "\n " .join (lines )
44
+ )
20
45
21
46
def test_default (testdir : pytest .Testdir ) -> None :
22
47
testdir .makepyfile (
@@ -112,10 +137,8 @@ async def test_multiple_browsers(page):
112
137
113
138
114
139
def test_browser_context_args (testdir : pytest .Testdir ) -> None :
115
- testdir . makeconftest (
140
+ makeconftest (testdir ,
116
141
"""
117
- import pytest
118
-
119
142
@pytest.fixture(scope="session")
120
143
def browser_context_args():
121
144
return {"user_agent": "foobar"}
@@ -134,7 +157,7 @@ async def test_browser_context_args(page):
134
157
135
158
136
159
def test_user_defined_browser_context_args (testdir : pytest .Testdir ) -> None :
137
- testdir . makeconftest (
160
+ makeconftest (testdir ,
138
161
"""
139
162
import pytest
140
163
@@ -159,7 +182,7 @@ async def test_browser_context_args(page):
159
182
160
183
161
184
def test_user_defined_browser_context_args_clear_again (testdir : pytest .Testdir ) -> None :
162
- testdir . makeconftest (
185
+ makeconftest (testdir ,
163
186
"""
164
187
import pytest
165
188
@@ -428,7 +451,7 @@ async def test_base_url(page):
428
451
429
452
430
453
def test_browser_context_args_device (testdir : pytest .Testdir ) -> None :
431
- testdir . makeconftest (
454
+ makeconftest (testdir ,
432
455
"""
433
456
import pytest
434
457
@@ -451,7 +474,7 @@ async def test_browser_context_args(page):
451
474
452
475
453
476
def test_launch_persistent_context_session (testdir : pytest .Testdir ) -> None :
454
- testdir . makeconftest (
477
+ makeconftest (testdir ,
455
478
"""
456
479
import pytest_asyncio
457
480
from playwright.sync_api import BrowserType
@@ -485,7 +508,7 @@ async def test_browser_context_args(page):
485
508
486
509
487
510
def test_context_page_on_session_level (testdir : pytest .Testdir ) -> None :
488
- testdir . makeconftest (
511
+ makeconftest (testdir ,
489
512
"""
490
513
import pytest
491
514
from playwright.sync_api import Browser, BrowserContext
@@ -529,7 +552,7 @@ async def test_b(page):
529
552
530
553
531
554
def test_launch_persistent_context_function (testdir : pytest .Testdir ) -> None :
532
- testdir . makeconftest (
555
+ makeconftest (testdir ,
533
556
"""
534
557
import pytest
535
558
from playwright.sync_api import BrowserType
@@ -751,7 +774,7 @@ def _assert_folder_structure(root: str, expected: str) -> None:
751
774
752
775
753
776
def test_is_able_to_set_expect_timeout_via_conftest (testdir : pytest .Testdir ) -> None :
754
- testdir . makeconftest (
777
+ makeconftest (testdir ,
755
778
"""
756
779
from playwright.async_api import expect
757
780
expect.set_options(timeout=1111)
0 commit comments