Skip to content

Commit be71a81

Browse files
committed
fix env in test_urllib
1 parent f0490ab commit be71a81

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

Lib/test/test_urllib.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,11 @@ def test_read_bogus(self):
419419
Content-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):
448455
Connection: 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

Comments
 (0)