66from tempfile import NamedTemporaryFile
77
88import pytest
9- from playwright .async_api import Dialog , Page as PlaywrightPage , TimeoutError
9+ from playwright .async_api import (
10+ Dialog ,
11+ Page as PlaywrightPage ,
12+ TimeoutError as PlaywrightTimeoutError ,
13+ )
1014from scrapy import Spider , Request , FormRequest
1115from scrapy .http .response .html import HtmlResponse
1216
@@ -21,6 +25,7 @@ def get_mimetype(file):
2125 ["file" , "--mime-type" , "--brief" , file .name ],
2226 stdout = subprocess .PIPE ,
2327 universal_newlines = True ,
28+ check = False ,
2429 ).stdout .strip ()
2530
2631
@@ -162,7 +167,7 @@ async def test_timeout(self):
162167 async with make_handler (settings_dict ) as handler :
163168 with MockServer () as server :
164169 req = Request (server .urljoin ("/delay/2" ), meta = {"playwright" : True })
165- with pytest .raises (TimeoutError ):
170+ with pytest .raises (PlaywrightTimeoutError ):
166171 await handler ._download_request (req , Spider ("foo" ))
167172
168173 @pytest .mark .asyncio
@@ -184,7 +189,7 @@ async def test_context_kwargs(self):
184189 ],
185190 },
186191 )
187- with pytest .raises (TimeoutError ):
192+ with pytest .raises (PlaywrightTimeoutError ):
188193 await handler ._download_request (req , Spider ("foo" ))
189194
190195 @pytest .mark .asyncio
@@ -263,10 +268,12 @@ async def test_user_agent(self):
263268 @pytest .mark .asyncio
264269 async def test_use_playwright_headers (self ):
265270 """Ignore Scrapy headers"""
271+ from scrapy_playwright .headers import use_playwright_headers
272+
266273 settings_dict = {
267274 "PLAYWRIGHT_BROWSER_TYPE" : self .browser_type ,
268275 "PLAYWRIGHT_CONTEXTS" : {"default" : {"user_agent" : self .browser_type }},
269- "PLAYWRIGHT_PROCESS_REQUEST_HEADERS" : "scrapy_playwright.headers. use_playwright_headers" , # noqa: E501
276+ "PLAYWRIGHT_PROCESS_REQUEST_HEADERS" : use_playwright_headers ,
270277 }
271278 async with make_handler (settings_dict ) as handler :
272279 with MockServer () as server :
0 commit comments