Skip to content

Commit 5d04870

Browse files
authored
Remove pytest-asyncio (#252)
1 parent 19d635b commit 5d04870

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
@@ -15,7 +15,6 @@
1515

1616

1717
class MixinTestCaseMultipleContexts:
18-
@pytest.mark.asyncio
1918
async def test_context_kwargs(self):
2019
settings_dict = {
2120
"PLAYWRIGHT_BROWSER_TYPE": self.browser_type,
@@ -38,7 +37,6 @@ async def test_context_kwargs(self):
3837
with pytest.raises(PlaywrightTimeoutError):
3938
await handler._download_request(req, Spider("foo"))
4039

41-
@pytest.mark.asyncio
4240
async def test_contexts_max_pages(self):
4341
settings = {
4442
"PLAYWRIGHT_BROWSER_TYPE": self.browser_type,
@@ -73,7 +71,6 @@ async def test_contexts_max_pages(self):
7371

7472
assert handler.stats.get_value("playwright/page_count/max_concurrent") == 4
7573

76-
@pytest.mark.asyncio
7774
async def test_max_contexts(self):
7875
def cb_close_context(task):
7976
response = task.result()
@@ -108,7 +105,6 @@ def cb_close_context(task):
108105

109106
assert handler.stats.get_value("playwright/context_count/max_concurrent") == 4
110107

111-
@pytest.mark.asyncio
112108
async def test_contexts_startup(self):
113109
settings = {
114110
"PLAYWRIGHT_BROWSER_TYPE": self.browser_type,
@@ -147,7 +143,6 @@ async def test_contexts_startup(self):
147143
assert cookie["value"] == "bar"
148144
assert cookie["domain"] == "example.org"
149145

150-
@pytest.mark.asyncio
151146
async def test_persistent_context(self):
152147
temp_dir = f"{tempfile.gettempdir()}/{uuid4()}"
153148
settings = {
@@ -166,7 +161,6 @@ async def test_persistent_context(self):
166161
assert handler.context_wrappers["persistent"].persistent
167162
assert not hasattr(handler, "browser")
168163

169-
@pytest.mark.asyncio
170164
async def test_mixed_persistent_contexts(self):
171165
temp_dir = f"{tempfile.gettempdir()}/{uuid4()}"
172166
settings = {
@@ -189,7 +183,6 @@ async def test_mixed_persistent_contexts(self):
189183
assert not handler.context_wrappers["non-persistent"].persistent
190184
assert isinstance(handler.browser, Browser)
191185

192-
@pytest.mark.asyncio
193186
async def test_contexts_dynamic(self):
194187
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
195188
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
@@ -22,7 +22,6 @@ def inject_fixtures(self, caplog):
2222
caplog.set_level(logging.DEBUG)
2323
self._caplog = caplog
2424

25-
@pytest.mark.asyncio
2625
async def test_get_page_content_ok(self):
2726
expected_content = "lorem ipsum"
2827
page = AsyncMock()
@@ -36,7 +35,6 @@ async def test_get_page_content_ok(self):
3635
)
3736
assert content == expected_content
3837

39-
@pytest.mark.asyncio
4038
async def test_get_page_content_retry_known_exception(self):
4139
expected_content = "lorem ipsum"
4240
page = AsyncMock()
@@ -57,7 +55,6 @@ async def test_get_page_content_retry_known_exception(self):
5755
" content because the page is navigating and changing the content.'",
5856
) in self._caplog.record_tuples
5957

60-
@pytest.mark.asyncio
6158
async def test_get_page_content_reraise_unknown_exception(self):
6259
expected_exception_message = "nope"
6360
page = AsyncMock()
@@ -87,7 +84,6 @@ def body_str(charset: str, content: str = "áéíóú") -> str:
8784
</html>
8885
""".strip()
8986

90-
@pytest.mark.asyncio
9187
async def test_encode_from_headers(self):
9288
"""Charset declared in headers takes precedence"""
9389
text = self.body_str(charset="gb2312")
@@ -98,23 +94,20 @@ async def test_encode_from_headers(self):
9894
assert encoding == "cp1252"
9995
assert body == text.encode(encoding)
10096

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

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

117-
@pytest.mark.asyncio
118111
async def test_encode_mismatch(self):
119112
"""Charset declared in headers and body do not match, and the headers
120113
one fails to encode: use the one in the body (first one that works)
@@ -129,7 +122,6 @@ async def test_encode_mismatch(self):
129122

130123

131124
class TestHeaderValue(IsolatedAsyncioTestCase):
132-
@pytest.mark.asyncio
133125
async def test_get_header_ok(self):
134126
async def _identity(x):
135127
return x
@@ -147,7 +139,6 @@ async def test_get_header_exception(self):
147139

148140

149141
class TestMaybeAwait(IsolatedAsyncioTestCase):
150-
@pytest.mark.asyncio
151142
async def test_maybe_await(self):
152143
async def _awaitable_identity(x):
153144
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)