diff --git a/tests/mockserver.py b/tests/mockserver.py index 35ff02a0..6487a80e 100644 --- a/tests/mockserver.py +++ b/tests/mockserver.py @@ -59,6 +59,9 @@ def do_GET(self) -> None: if parsed_path.path == "/headers": self._send_json(dict(self.headers)) + elif parsed_path.path == "/status/204": + self.send_response(204) + self.end_headers() elif parsed_path.path == "/redirect2": self.send_response(302) self.send_header("Content-Length", "0") diff --git a/tests/tests_asyncio/test_playwright_requests.py b/tests/tests_asyncio/test_playwright_requests.py index fc972947..32dd660f 100644 --- a/tests/tests_asyncio/test_playwright_requests.py +++ b/tests/tests_asyncio/test_playwright_requests.py @@ -465,6 +465,23 @@ async def cancel_download(download): f" exc_type={type(excinfo.value)} exc_msg={str(excinfo.value)}", ) in self._caplog.record_tuples + @allow_windows + async def test_fail_status_204(self): + async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler: + with MockServer() as server: + request = Request( + url=server.urljoin("/status/204"), + meta={"playwright": True}, + ) + with pytest.raises(PlaywrightError) as excinfo: + await handler._download_request(request, Spider("foo")) + assert ( + "scrapy-playwright", + logging.WARNING, + f"Closing page due to failed request: {request}" + f" exc_type={type(excinfo.value)} exc_msg={str(excinfo.value)}", + ) in self._caplog.record_tuples + class TestCaseChromium(IsolatedAsyncioTestCase, MixinTestCase): browser_type = "chromium"