Introduce test.test_support.TransientResource. It's a context manager to

surround calls to resources that may or may not be available.  Specifying the
expected exception and attributes to be raised if the resource is not available
prevents overly broad catching of exceptions.

This is meant to help suppress spurious failures by raising
test.test_support.ResourceDenied if the exception matches.  It would probably
be good to go through the various network tests and surround the calls to catch
connection timeouts (as done with test_socket_ssl in this commit).
This commit is contained in:
Brett Cannon 2007-03-08 23:58:11 +00:00
parent 9b2a109540
commit a30fcb4dae
4 changed files with 39 additions and 1 deletions

View file

@ -27,7 +27,8 @@ def test_basic():
print "didn't raise TypeError"
socket.RAND_add("this is a random string", 75.0)
f = urllib.urlopen('https://sf.net')
with test_support.TransientResource(IOError, errno=errno.ETIMEDOUT):
f = urllib.urlopen('https://sf.net')
buf = f.read()
f.close()