@@ -260,25 +260,22 @@ def test_create_server_4(self):
260260 with sock :
261261 addr = sock .getsockname ()
262262
263+ with self .assertRaises (OSError ) as cm :
264+ self .loop .run_until_complete (
265+ self .loop .create_server (object , * addr )
266+ )
263267 if sys .platform == "win32" :
264- with self .assertRaises (OSError ) as cm :
265- self .loop .run_until_complete (
266- self .loop .create_server (object , * addr )
267- )
268268 self .assertEqual (
269269 getattr (cm .exception , "winerror" , None )
270270 or cm .exception .errno ,
271271 10048 ,
272272 )
273273 else :
274- with self .assertRaisesRegex (
275- OSError ,
274+ self .assertRegex (
275+ str ( cm . exception ) ,
276276 r"error while attempting.*\('127.*:"
277277 r"( \[errno \d+\])? address( already)? in use" ,
278- ):
279- self .loop .run_until_complete (
280- self .loop .create_server (object , * addr )
281- )
278+ )
282279
283280 def test_create_server_5 (self ):
284281 # Test that create_server sets the TCP_IPV6ONLY flag,
@@ -581,17 +578,16 @@ async def client():
581578 await self .wait_closed (writer )
582579
583580 async def runner ():
581+ with self .assertRaises (OSError ) as cm :
582+ await client ()
584583 if sys .platform == "win32" :
585- with self .assertRaises (OSError ) as cm :
586- await client ()
587584 self .assertEqual (
588585 getattr (cm .exception , "winerror" , None )
589586 or cm .exception .errno ,
590587 10038 ,
591588 )
592589 else :
593- with self .assertRaisesRegex (OSError , "Bad file" ):
594- await client ()
590+ self .assertRegex (str (cm .exception ), "Bad file" )
595591
596592 self .loop .run_until_complete (runner ())
597593
0 commit comments