Skip to content

Commit 1b22c81

Browse files
committed
Merge remote-tracking branch 'origin/main' into close-inactive-contexts
2 parents a87e0bb + 5d04870 commit 1b22c81

File tree

6 files changed

+0
-48
lines changed

6 files changed

+0
-48
lines changed

tests/tests_asyncio/test_browser_contexts.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def inject_fixtures(self, caplog):
2121
caplog.set_level(logging.DEBUG)
2222
self._caplog = caplog
2323

24-
@pytest.mark.asyncio
2524
async def test_context_kwargs(self):
2625
settings_dict = {
2726
"PLAYWRIGHT_BROWSER_TYPE": self.browser_type,
@@ -44,7 +43,6 @@ async def test_context_kwargs(self):
4443
with pytest.raises(PlaywrightTimeoutError):
4544
await handler._download_request(req, Spider("foo"))
4645

47-
@pytest.mark.asyncio
4846
async def test_contexts_max_pages(self):
4947
settings = {
5048
"PLAYWRIGHT_BROWSER_TYPE": self.browser_type,
@@ -79,7 +77,6 @@ async def test_contexts_max_pages(self):
7977

8078
assert handler.stats.get_value("playwright/page_count/max_concurrent") == 4
8179

82-
@pytest.mark.asyncio
8380
async def test_max_contexts(self):
8481
def cb_close_context(task):
8582
response = task.result()
@@ -114,7 +111,6 @@ def cb_close_context(task):
114111

115112
assert handler.stats.get_value("playwright/context_count/max_concurrent") == 4
116113

117-
@pytest.mark.asyncio
118114
async def test_contexts_startup(self):
119115
settings = {
120116
"PLAYWRIGHT_BROWSER_TYPE": self.browser_type,
@@ -153,7 +149,6 @@ async def test_contexts_startup(self):
153149
assert cookie["value"] == "bar"
154150
assert cookie["domain"] == "example.org"
155151

156-
@pytest.mark.asyncio
157152
async def test_persistent_context(self):
158153
temp_dir = f"{tempfile.gettempdir()}/{uuid4()}"
159154
settings = {
@@ -172,7 +167,6 @@ async def test_persistent_context(self):
172167
assert handler.context_wrappers["persistent"].persistent
173168
assert not hasattr(handler, "browser")
174169

175-
@pytest.mark.asyncio
176170
async def test_mixed_persistent_contexts(self):
177171
temp_dir = f"{tempfile.gettempdir()}/{uuid4()}"
178172
settings = {
@@ -195,7 +189,6 @@ async def test_mixed_persistent_contexts(self):
195189
assert not handler.context_wrappers["non-persistent"].persistent
196190
assert isinstance(handler.browser, Browser)
197191

198-
@pytest.mark.asyncio
199192
async def test_contexts_dynamic(self):
200193
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
201194
assert len(handler.context_wrappers) == 0

tests/tests_asyncio/test_headers.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111

1212
class MixinProcessHeadersTestCase:
13-
@pytest.mark.asyncio
1413
async def test_user_agent(self):
1514
settings_dict = {
1615
"PLAYWRIGHT_BROWSER_TYPE": self.browser_type,
@@ -40,7 +39,6 @@ async def test_user_agent(self):
4039
headers = {key.lower(): value for key, value in headers.items()}
4140
assert headers["user-agent"] == "foobar"
4241

43-
@pytest.mark.asyncio
4442
async def test_playwright_headers(self):
4543
"""Ignore Scrapy headers"""
4644
settings_dict = {
@@ -65,7 +63,6 @@ async def test_playwright_headers(self):
6563
assert "asdf" not in req.headers
6664
assert b"asdf" not in req.headers
6765

68-
@pytest.mark.asyncio
6966
async def test_use_custom_headers(self):
7067
"""Custom header processing function"""
7168

tests/tests_asyncio/test_page_methods.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def get_mimetype(file):
2424

2525

2626
class TestPageMethods(IsolatedAsyncioTestCase):
27-
@pytest.mark.asyncio
2827
async def test_page_methods(self):
2928
screenshot = PageMethod("screenshot", "foo", 123, path="/tmp/file", type="png")
3029
assert screenshot.method == "screenshot"
@@ -40,7 +39,6 @@ def inject_fixtures(self, caplog):
4039
caplog.set_level(logging.DEBUG)
4140
self._caplog = caplog
4241

43-
@pytest.mark.asyncio
4442
async def test_page_non_page_method(self):
4543
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
4644
with StaticMockServer() as server:
@@ -65,7 +63,6 @@ async def test_page_non_page_method(self):
6563
f"Ignoring {repr(obj)}: expected PageMethod, got {repr(type(obj))}",
6664
) in self._caplog.record_tuples
6765

68-
@pytest.mark.asyncio
6966
async def test_page_mixed_page_methods(self):
7067
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
7168
with StaticMockServer() as server:
@@ -92,7 +89,6 @@ async def test_page_mixed_page_methods(self):
9289
assert not req.meta["playwright_page_methods"]["is_closed"].result
9390
assert req.meta["playwright_page_methods"]["title"].result == "Awesome site"
9491

95-
@pytest.mark.asyncio
9692
async def test_page_method_navigation(self):
9793
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
9894
with StaticMockServer() as server:
@@ -114,7 +110,6 @@ async def test_page_method_navigation(self):
114110
text = resp.css("p::text").get()
115111
assert text == "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
116112

117-
@pytest.mark.asyncio
118113
async def test_page_method_infinite_scroll(self):
119114
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
120115
with StaticMockServer() as server:
@@ -141,7 +136,6 @@ async def test_page_method_infinite_scroll(self):
141136
assert_correct_response(resp, req)
142137
assert len(resp.css("div.quote")) == 30
143138

144-
@pytest.mark.asyncio
145139
async def test_page_method_screenshot(self):
146140
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
147141
with NamedTemporaryFile(mode="w+b") as png_file:
@@ -161,7 +155,6 @@ async def test_page_method_screenshot(self):
161155
assert png_file.file.read() == req.meta["playwright_page_methods"]["png"].result
162156
assert get_mimetype(png_file) == "image/png"
163157

164-
@pytest.mark.asyncio
165158
async def test_page_method_pdf(self):
166159
if self.browser_type != "chromium":
167160
pytest.skip("PDF generation is supported only in Chromium")

tests/tests_asyncio/test_playwright_requests.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def inject_fixtures(self, caplog):
4141
caplog.set_level(logging.DEBUG)
4242
self._caplog = caplog
4343

44-
@pytest.mark.asyncio
4544
async def test_basic_response(self):
4645
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
4746
with StaticMockServer() as server:
@@ -53,10 +52,8 @@ async def test_basic_response(self):
5352
assert resp.css("a::text").getall() == ["Lorem Ipsum", "Infinite Scroll"]
5453
assert isinstance(resp.meta["playwright_page"], PlaywrightPage)
5554
assert resp.meta["playwright_page"].url == resp.url
56-
5755
await resp.meta["playwright_page"].close()
5856

59-
@pytest.mark.asyncio
6057
async def test_post_request(self):
6158
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
6259
with MockServer() as server:
@@ -68,7 +65,6 @@ async def test_post_request(self):
6865
assert_correct_response(resp, req)
6966
assert "Request body: foo=bar" in resp.text
7067

71-
@pytest.mark.asyncio
7268
async def test_timeout_error(self):
7369
settings_dict = {
7470
"PLAYWRIGHT_BROWSER_TYPE": self.browser_type,
@@ -86,7 +82,6 @@ async def test_timeout_error(self):
8682
f" exc_type={type(excinfo.value)} exc_msg={str(excinfo.value)}",
8783
) in self._caplog.record_tuples
8884

89-
@pytest.mark.asyncio
9085
async def test_retry_page_content_still_navigating(self):
9186
if self.browser_type != "chromium":
9287
pytest.skip("Only Chromium seems to redirect meta tags within the same goto call")
@@ -108,7 +103,6 @@ async def test_retry_page_content_still_navigating(self):
108103
) in self._caplog.record_tuples
109104

110105
@patch("scrapy_playwright.handler.logger")
111-
@pytest.mark.asyncio
112106
async def test_route_continue_exception(self, logger):
113107
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
114108
scrapy_request = Request(url="https://example.org", method="GET")
@@ -159,7 +153,6 @@ async def test_route_continue_exception(self, logger):
159153
with pytest.raises(PlaywrightError):
160154
await req_handler(route, playwright_request)
161155

162-
@pytest.mark.asyncio
163156
async def test_event_handler_dialog_callable(self):
164157
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
165158
with StaticMockServer() as server:
@@ -181,7 +174,6 @@ async def test_event_handler_dialog_callable(self):
181174

182175
assert spider.dialog_message == "foobar"
183176

184-
@pytest.mark.asyncio
185177
async def test_event_handler_dialog_str(self):
186178
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
187179
with StaticMockServer() as server:
@@ -203,7 +195,6 @@ async def test_event_handler_dialog_str(self):
203195

204196
assert spider.dialog_message == "foobar"
205197

206-
@pytest.mark.asyncio
207198
async def test_event_handler_dialog_missing(self):
208199
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
209200
with StaticMockServer() as server:
@@ -227,7 +218,6 @@ async def test_event_handler_dialog_missing(self):
227218
) in self._caplog.record_tuples
228219
assert getattr(spider, "dialog_message", None) is None
229220

230-
@pytest.mark.asyncio
231221
async def test_response_attributes(self):
232222
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
233223
with MockServer() as server:
@@ -239,7 +229,6 @@ async def test_response_attributes(self):
239229

240230
assert response.ip_address == ip_address(server.address)
241231

242-
@pytest.mark.asyncio
243232
async def test_page_goto_kwargs_referer(self):
244233
if self.browser_type != "chromium":
245234
pytest.skip("referer as goto kwarg seems to work only with chromium :shrug:")
@@ -258,7 +247,6 @@ async def test_page_goto_kwargs_referer(self):
258247
headers = json.loads(response.css("pre::text").get())
259248
assert headers["Referer"] == fake_referer
260249

261-
@pytest.mark.asyncio
262250
async def test_navigation_returns_none(self):
263251
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
264252
with MockServer():
@@ -274,7 +262,6 @@ async def test_navigation_returns_none(self):
274262
assert not response.headers
275263
assert response.status == 200
276264

277-
@pytest.mark.asyncio
278265
async def test_abort_requests(self):
279266
async def should_abort_request_async(request):
280267
return request.resource_type == "image"
@@ -307,7 +294,6 @@ def should_abort_request_sync(request):
307294
assert handler.stats.get_value(f"{resp_prefix}/resource_type/image") is None
308295
assert handler.stats.get_value(f"{req_prefix}/aborted") == 3
309296

310-
@pytest.mark.asyncio
311297
async def test_page_initialization_ok(self):
312298
async def init_page(page, _request):
313299
await page.set_extra_http_headers({"Extra-Header": "Qwerty"})
@@ -328,7 +314,6 @@ async def init_page(page, _request):
328314
headers = {key.lower(): value for key, value in headers.items()}
329315
assert headers["extra-header"] == "Qwerty"
330316

331-
@pytest.mark.asyncio
332317
async def test_page_initialization_fail(self):
333318
async def init_page(page, _request, _missing):
334319
await page.set_extra_http_headers({"Extra-Header": "Qwerty"})
@@ -355,7 +340,6 @@ async def init_page(page, _request, _missing):
355340
assert f"[Context=default] Page init callback exception for {req!r}" in entry[2]
356341
assert "init_page() missing 1 required positional argument: '_missing'" in entry[2]
357342

358-
@pytest.mark.asyncio
359343
async def test_redirect(self):
360344
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
361345
with MockServer() as server:
@@ -373,7 +357,6 @@ async def test_redirect(self):
373357
server.urljoin("/redirect"),
374358
]
375359

376-
@pytest.mark.asyncio
377360
async def test_logging_record_spider(self):
378361
"""Make sure at least one log record has the spider as an attribute
379362
(records sent before opening the spider will not have it).
@@ -386,7 +369,6 @@ async def test_logging_record_spider(self):
386369

387370
assert any(getattr(rec, "spider", None) is spider for rec in self._caplog.records)
388371

389-
@pytest.mark.asyncio
390372
async def test_download_file(self):
391373
settings_dict = {
392374
"PLAYWRIGHT_BROWSER_TYPE": self.browser_type,
@@ -402,7 +384,6 @@ async def test_download_file(self):
402384
assert response.body.startswith(b"%PDF-1.5")
403385
assert handler.stats.get_value("playwright/download_count") == 1
404386

405-
@pytest.mark.asyncio
406387
async def test_download_file_delay_ok(self):
407388
settings_dict = {
408389
"PLAYWRIGHT_BROWSER_TYPE": self.browser_type,
@@ -419,7 +400,6 @@ async def test_download_file_delay_ok(self):
419400
assert response.body.startswith(b"%PDF-1.5")
420401
assert handler.stats.get_value("playwright/download_count") == 1
421402

422-
@pytest.mark.asyncio
423403
async def test_download_file_delay_error(self):
424404
settings_dict = {
425405
"PLAYWRIGHT_BROWSER_TYPE": self.browser_type,
@@ -440,7 +420,6 @@ async def test_download_file_delay_error(self):
440420
f" exc_type={type(excinfo.value)} exc_msg={str(excinfo.value)}",
441421
) in self._caplog.record_tuples
442422

443-
@pytest.mark.asyncio
444423
async def test_download_file_failure(self):
445424
if self.browser_type != "chromium":
446425
pytest.skip()

tests/tests_asyncio/test_utils.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def inject_fixtures(self, caplog):
2424
caplog.set_level(logging.DEBUG)
2525
self._caplog = caplog
2626

27-
@pytest.mark.asyncio
2827
async def test_get_page_content_ok(self):
2928
expected_content = "lorem ipsum"
3029
page = AsyncMock()
@@ -38,7 +37,6 @@ async def test_get_page_content_ok(self):
3837
)
3938
assert content == expected_content
4039

41-
@pytest.mark.asyncio
4240
async def test_get_page_content_retry_known_exception(self):
4341
expected_content = "lorem ipsum"
4442
page = AsyncMock()
@@ -59,7 +57,6 @@ async def test_get_page_content_retry_known_exception(self):
5957
" content because the page is navigating and changing the content.'",
6058
) in self._caplog.record_tuples
6159

62-
@pytest.mark.asyncio
6360
async def test_get_page_content_reraise_unknown_exception(self):
6461
expected_exception_message = "nope"
6562
page = AsyncMock()
@@ -89,7 +86,6 @@ def body_str(charset: str, content: str = "áéíóú") -> str:
8986
</html>
9087
""".strip()
9188

92-
@pytest.mark.asyncio
9389
async def test_encode_from_headers(self):
9490
"""Charset declared in headers takes precedence"""
9591
text = self.body_str(charset="gb2312")
@@ -100,23 +96,20 @@ async def test_encode_from_headers(self):
10096
assert encoding == "cp1252"
10197
assert body == text.encode(encoding)
10298

103-
@pytest.mark.asyncio
10499
async def test_encode_from_body(self):
105100
"""No charset declared in headers, use the one declared in the body"""
106101
text = self.body_str(charset="gb2312")
107102
body, encoding = _encode_body(headers=Headers({}), text=text)
108103
assert encoding == "gb18030"
109104
assert body == text.encode(encoding)
110105

111-
@pytest.mark.asyncio
112106
async def test_encode_fallback_utf8(self):
113107
"""No charset declared, use utf-8 as fallback"""
114108
text = "<html>áéíóú</html>"
115109
body, encoding = _encode_body(headers=Headers(), text=text)
116110
assert encoding == "utf-8"
117111
assert body == text.encode(encoding)
118112

119-
@pytest.mark.asyncio
120113
async def test_encode_mismatch(self):
121114
"""Charset declared in headers and body do not match, and the headers
122115
one fails to encode: use the one in the body (first one that works)
@@ -131,7 +124,6 @@ async def test_encode_mismatch(self):
131124

132125

133126
class TestHeaderValue(IsolatedAsyncioTestCase):
134-
@pytest.mark.asyncio
135127
async def test_get_header_value(self):
136128
async def _identity(x):
137129
return x
@@ -148,7 +140,6 @@ async def _identity(x):
148140

149141

150142
class TestMaybeAwait(IsolatedAsyncioTestCase):
151-
@pytest.mark.asyncio
152143
async def test_maybe_await(self):
153144
async def _awaitable_identity(x):
154145
return x

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ envlist = bandit,black,flake8,typing,pylint,py,py-twisted
44
[testenv]
55
deps =
66
pytest==7.4.0
7-
pytest_asyncio==0.21.1
87
pytest_cov==4.1.0
98
pytest_twisted==1.14
109
commands =

0 commit comments

Comments
 (0)