()
| 2949 | |
| 2950 | |
| 2951 | def _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 | |
| 2996 | if __name__ == "__main__": |
no test coverage detected
searching dependent graphs…