diff -r 67dc99a989cd Lib/doctest.py --- a/Lib/doctest.py Mon Jun 25 20:57:36 2012 -0700 +++ b/Lib/doctest.py Tue Jun 26 08:15:01 2012 +0200 @@ -2766,20 +2766,26 @@ name, _ = os.path.splitext(name) print("usage: {0} [-v] file ...".format(name)) return 2 + failures = False for filename in testfiles: - if filename.endswith(".py"): - # It is a module -- insert its dir into sys.path and try to - # import it. If it is part of a package, that possibly - # won't work because of package imports. - dirname, filename = os.path.split(filename) - sys.path.insert(0, dirname) - m = __import__(filename[:-3]) - del sys.path[0] - failures, _ = testmod(m) - else: - failures, _ = testfile(filename, module_relative=False) - if failures: - return 1 + try: + if filename.endswith(".py"): + # It is a module -- insert its dir into sys.path and try to + # import it. If it is part of a package, that possibly + # won't work because of package imports. + dirname, filename = os.path.split(filename) + sys.path.insert(0, dirname) + m = __import__(filename[:-3]) + del sys.path[0] + failure, _ = testmod(m) + else: + failure, _ = testfile(filename, module_relative=False) + failures |= failure + except IOError as e: + print "Cannot read '{0}': {1}".format(filename, e) + failures = True + if failures: + return 1 return 0