diff -r 01d180987d90 Lib/doctest.py --- a/Lib/doctest.py Tue Jun 26 20:05:12 2012 +0800 +++ b/Lib/doctest.py Wed Jun 27 07:23:34 2012 +0200 @@ -2767,17 +2767,21 @@ print("usage: {0} [-v] file ...".format(name)) return 2 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) + 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] + failures, _ = testmod(m) + else: + failures, _ = testfile(filename, module_relative=False) + except IOError as e: + print("Cannot read '{0}': {1}".format(filename, e)) + failures = True if failures: return 1 return 0