diff -r ebe2072e5472 Lib/doctest.py --- a/Lib/doctest.py Fri Dec 12 09:30:18 2014 +0200 +++ b/Lib/doctest.py Fri Dec 12 09:04:09 2014 +0100 @@ -2738,6 +2738,11 @@ """, } +def _print_files_report(read, unread): + print('Test files read successfully:', read) + if unread: + print('Unreadable files:', unread) + def _test(): parser = argparse.ArgumentParser(description="doctest runner") @@ -2764,22 +2769,35 @@ options |= OPTIONFLAGS_BY_NAME[option] if args.fail_fast: options |= FAIL_FAST + read_files = 0 + unread_files = 0 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, verbose=verbose, optionflags=options) + 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, verbose=verbose, optionflags=options) + else: + failures, _ = testfile(filename, module_relative=False, + verbose=verbose, optionflags=options) + if failures: + _print_files_report(read_files, unread_files) + return 1 + except OSError as e: + print("Cannot read '{0}': {1}".format(filename, e)) + unread_files += 1 else: - failures, _ = testfile(filename, module_relative=False, - verbose=verbose, optionflags=options) - if failures: - return 1 - return 0 + read_files += 1 + if unread_files: + _print_files_report(read_files, unread_files) + return 3 + else: + return 0 if __name__ == "__main__":