@@ -419,7 +419,11 @@ def test_read_bogus(self):
419419Content-Type: text/html; charset=iso-8859-1
420420''' , mock_close = True )
421421 try :
422- self .assertRaises (OSError , urllib .request .urlopen , "http://python.org/" )
422+ with self .assertRaises (OSError ) as exc_info :
423+ with urllib .request .urlopen ("http://python.org/" ):
424+ pass
425+ with exc_info .exception :
426+ pass
423427 finally :
424428 self .unfakehttp ()
425429
@@ -434,8 +438,11 @@ def test_invalid_redirect(self):
434438''' , mock_close = True )
435439 try :
436440 msg = "Redirection to url 'file:"
437- with self .assertRaisesRegex (urllib .error .HTTPError , msg ):
438- urllib .request .urlopen ("http://python.org/" )
441+ with self .assertRaisesRegex (urllib .error .HTTPError , msg ) as exc_info :
442+ with urllib .request .urlopen ("http://python.org/" ):
443+ pass
444+ with exc_info .exception :
445+ pass
439446 finally :
440447 self .unfakehttp ()
441448
@@ -448,8 +455,11 @@ def test_redirect_limit_independent(self):
448455Connection: close
449456''' , mock_close = True )
450457 try :
451- self .assertRaises (urllib .error .HTTPError , urllib .request .urlopen ,
452- "http://something" )
458+ with self .assertRaises (urllib .error .HTTPError ) as exc_info :
459+ with urllib .request .urlopen ("http://something" ):
460+ pass
461+ with exc_info .exception :
462+ pass
453463 finally :
454464 self .unfakehttp ()
455465
@@ -529,10 +539,10 @@ def setUp(self):
529539 "QOjdAAAAAXNSR0IArs4c6QAAAA9JREFUCNdj%0AYGBg%2BP//PwAGAQL%2BCm8 "
530540 "vHgAAAABJRU5ErkJggg%3D%3D%0A%20" )
531541
532- self .text_url_resp = urllib .request .urlopen (self .text_url )
533- self .text_url_base64_resp = urllib .request .urlopen (
534- self .text_url_base64 )
535- self .image_url_resp = urllib .request .urlopen (self .image_url )
542+ self .text_url_resp = self . enterContext ( urllib .request .urlopen (self .text_url ) )
543+ self .text_url_base64_resp = self . enterContext ( urllib .request .urlopen (
544+ self .text_url_base64 ))
545+ self .image_url_resp = self . enterContext ( urllib .request .urlopen (self .image_url ) )
536546
537547 def test_interface (self ):
538548 # Make sure object returned by urlopen() has the specified methods
0 commit comments