1 # Copyright (c) Microsoft Corporation. All rights reserved.
2 # Licensed under the MIT License.
4 from __future__ import absolute_import
9 from . import pytest, report
10 from .errors import UnsupportedToolError, UnsupportedCommandError
15 '_add_subparser': pytest.add_cli_subparser,
16 'discover': pytest.discover,
20 'discover': report.report_discovered,
30 Return the subcommand & tool to run, along with its args.
32 This defines the standard CLI for the different testing frameworks.
34 parser = argparse.ArgumentParser(
35 description='Run Python testing operations.',
38 cmdsubs = parser.add_subparsers(dest='cmd')
40 # Add "run" and "debug" subcommands when ready.
41 for cmdname in ['discover']:
42 sub = cmdsubs.add_parser(cmdname)
43 subsubs = sub.add_subparsers(dest='tool')
44 for toolname in sorted(TOOLS):
46 add_subparser = TOOLS[toolname]['_add_subparser']
49 subsub = add_subparser(cmdname, toolname, subsubs)
50 if cmdname == 'discover':
51 subsub.add_argument('--simple', action='store_true')
52 subsub.add_argument('--no-hide-stdio', dest='hidestdio',
54 subsub.add_argument('--pretty', action='store_true')
58 seppos = argv.index('--')
59 toolargs = argv[seppos + 1:]
63 args = parser.parse_args(argv)
68 parser.error('missing command')
72 parser.error('missing tool')
74 return tool, cmd, ns, toolargs
77 def main(toolname, cmdname, subargs, toolargs,
78 _tools=TOOLS, _reporters=REPORTERS):
80 tool = _tools[toolname]
82 raise UnsupportedToolError(toolname)
86 report_result = _reporters[cmdname]
88 raise UnsupportedCommandError(cmdname)
90 parents, result = run(toolargs, **subargs)
91 report_result(result, parents,
96 if __name__ == '__main__':
97 tool, cmd, subargs, toolargs = parse_args()
98 main(tool, cmd, subargs, toolargs)