MCPcopy Index your code
hub / github.com/python/cpython / _test

Function _test

Lib/doctest.py:2951–2993  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2949
2950
2951def _test():
2952 import argparse
2953
2954 parser = argparse.ArgumentParser(description="doctest runner", color=True)
2955 parser.add_argument('-v', '--verbose', action='store_true', default=False,
2956 help='print very verbose output for all tests')
2957 parser.add_argument('-o', '--option', action='append',
2958 choices=OPTIONFLAGS_BY_NAME.keys(), default=[],
2959 help=('specify a doctest option flag to apply'
2960 ' to the test run; may be specified more'
2961 ' than once to apply multiple options'))
2962 parser.add_argument('-f', '--fail-fast', action='store_true',
2963 help=('stop running tests after first failure (this'
2964 ' is a shorthand for -o FAIL_FAST, and is'
2965 ' in addition to any other -o options)'))
2966 parser.add_argument('file', nargs='+',
2967 help='file containing the tests to run')
2968 args = parser.parse_args()
2969 testfiles = args.file
2970 # Verbose used to be handled by the "inspect argv" magic in DocTestRunner,
2971 # but since we are using argparse we are passing it manually now.
2972 verbose = args.verbose
2973 options = 0
2974 for option in args.option:
2975 options |= OPTIONFLAGS_BY_NAME[option]
2976 if args.fail_fast:
2977 options |= FAIL_FAST
2978 for filename in testfiles:
2979 if filename.endswith(".py"):
2980 # It is a module -- insert its dir into sys.path and try to
2981 # import it. If it is part of a package, that possibly
2982 # won't work because of package imports.
2983 dirname, filename = os.path.split(filename)
2984 sys.path.insert(0, dirname)
2985 m = __import__(filename[:-3])
2986 del sys.path[0]
2987 failures, _ = testmod(m, verbose=verbose, optionflags=options)
2988 else:
2989 failures, _ = testfile(filename, module_relative=False,
2990 verbose=verbose, optionflags=options)
2991 if failures:
2992 return 1
2993 return 0
2994
2995
2996if __name__ == "__main__":

Callers 1

doctest.pyFile · 0.70

Calls 9

parse_argsMethod · 0.95
__import__Function · 0.85
testmodFunction · 0.85
testfileFunction · 0.85
add_argumentMethod · 0.45
keysMethod · 0.45
endswithMethod · 0.45
splitMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…