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 13:00:40 2012 +0200 @@ -216,8 +216,11 @@ # get_data() opens files as 'rb', so one must do the equivalent # conversion as universal newlines would do. return file_contents.replace(os.linesep, '\n'), filename - with open(filename) as f: - return f.read(), filename + try: + with open(filename) as f: + return f.read(), filename + except IOError as e: + sys.exit("Cannot read '{0}': {1}".format(filename, e)) # Use sys.stdout encoding for ouput. _encoding = getattr(sys.__stdout__, 'encoding', None) or 'utf-8'