1313
1414def get ():
1515path = os .path .sep .join ((os .path .dirname (os .path .abspath (__file__ )),'python.html' ))
16- url = 'file://{}' . format ( path )
16+ url = f 'file://{ path } '
1717
1818return session .get (url )
1919
2020
2121@pytest .fixture
2222def async_get (event_loop ):
23- """ AsyncSession cannot be created global since it will create
23+ """AsyncSession cannot be created global since it will create
2424 a different loop from pytest-asyncio. """
2525async_session = AsyncHTMLSession ()
2626async_session .mount ('file://' ,FileAdapter ())
@@ -54,8 +54,8 @@ def test_css_selector():
5454about = r .html .find ('#about' ,first = True )
5555
5656for menu_item in (
57- 'About' ,'Applications' ,'Quotes' ,'Getting Started' ,'Help' ,
58- 'Python Brochure'
57+ 'About' ,'Applications' ,'Quotes' ,'Getting Started' ,'Help' ,
58+ 'Python Brochure'
5959 ):
6060assert menu_item in about .text .split ('\n ' )
6161assert menu_item in about .full_text .split ('\n ' )
@@ -290,16 +290,24 @@ async def test_bare_js_async_eval():
290290
291291
292292def test_browser_session ():
293- """ Test browserinstaces is created and properly close when session is closed.
293+ """ Test browserinstances is created and properly close when session is closed.
294294 Note: session.close method need to be tested together with browser creation,
295- sinceno doing that willleft the browser running. """
295+ sincenot doing that willleave the browser running. """
296296session = HTMLSession ()
297297assert isinstance (session .browser ,Browser )
298- assert hasattr (session ,"loop" )== True
298+ assert hasattr (session ,"loop" )
299299session .close ()
300300# assert count_chromium_process() == 0
301301
302302
303+ def test_browser_process ():
304+ for _ in range (3 ):
305+ r = get ()
306+ r .html .render ()
307+
308+ assert r .html .page is None
309+
310+
303311@pytest .mark .asyncio
304312async def test_browser_session_fail ():
305313""" HTMLSession.browser should not be call within an existing event loop> """
@@ -308,21 +316,9 @@ async def test_browser_session_fail():
308316session .browser
309317
310318
311- def test_browser_process ():
312- for _ in range (3 ):
313- r = get ()
314- r .html .render ()
315-
316- assert r .html .page == None
317-
318-
319319@pytest .mark .asyncio
320320async def test_async_browser_session ():
321321session = AsyncHTMLSession ()
322322browser = await session .browser
323323assert isinstance (browser ,Browser )
324324await session .close ()
325-
326-
327- if __name__ == '__main__' :
328- test_containing ()