diff -r e5478b6b93b5 Lib/doctest.py --- a/Lib/doctest.py Sat Jun 23 10:06:56 2012 +0200 +++ b/Lib/doctest.py Mon Jun 25 15:18:28 2012 +0200 @@ -2767,17 +2767,20 @@ 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: + sys.exit("Cannot read '{0}': {1}".format(filename, e)) if failures: return 1 return 0