Merge "Add ostestr as a function"

This commit is contained in:
Jenkins 2016-09-21 12:59:50 +00:00 committed by Gerrit Code Review
commit 91e4c776fe
1 changed files with 17 additions and 13 deletions

View File

@ -144,7 +144,7 @@ def call_testr(regex, subunit, pretty, list_tests, slowest, parallel, concur,
failed = False failed = False
if not test_list: if not test_list:
print("No tests to run") print("No tests to run")
exit(1) return 1
# If pretty or subunit output is desired manually loop forever over # If pretty or subunit output is desired manually loop forever over
# test individually and generate the desired output in a linear series # test individually and generate the desired output in a linear series
# this avoids 1411804 while retaining most of the desired behavior # this avoids 1411804 while retaining most of the desired behavior
@ -168,13 +168,13 @@ def call_testr(regex, subunit, pretty, list_tests, slowest, parallel, concur,
except SystemExit as e: except SystemExit as e:
if e > 0: if e > 0:
print("Ran %s tests without failure" % count) print("Ran %s tests without failure" % count)
exit(1) return 1
else: else:
raise raise
count = count + 1 count = count + 1
if failed: if failed:
print("Ran %s tests without failure" % count) print("Ran %s tests without failure" % count)
exit(0) return 0
# If not until-failure special case call testr like normal # If not until-failure special case call testr like normal
elif pretty and not list_tests: elif pretty and not list_tests:
cmd.extend(others) cmd.extend(others)
@ -248,35 +248,35 @@ def _call_testr_with_list(opts, test_list, others):
return ec return ec
def main(): def ostestr(args):
opts, others = get_parser(sys.argv[1:]) opts, others = get_parser(args)
if opts.pretty and opts.subunit: if opts.pretty and opts.subunit:
msg = ('Subunit output and pretty output cannot be specified at the ' msg = ('Subunit output and pretty output cannot be specified at the '
'same time') 'same time')
print(msg) print(msg)
exit(2) return 2
if opts.list and opts.no_discover: if opts.list and opts.no_discover:
msg = ('you can not list tests when you are bypassing discovery to ' msg = ('you can not list tests when you are bypassing discovery to '
'run a single test') 'run a single test')
print(msg) print(msg)
exit(3) return 3
if not opts.parallel and opts.concurrency: if not opts.parallel and opts.concurrency:
msg = "You can't specify a concurrency to use when running serially" msg = "You can't specify a concurrency to use when running serially"
print(msg) print(msg)
exit(4) return 4
if (opts.pdb or opts.no_discover) and opts.until_failure: if (opts.pdb or opts.no_discover) and opts.until_failure:
msg = "You can not use until_failure mode with pdb or no-discover" msg = "You can not use until_failure mode with pdb or no-discover"
print(msg) print(msg)
exit(5) return 5
if ((opts.pdb or opts.no_discover) and if ((opts.pdb or opts.no_discover) and
(opts.blacklist_file or opts.whitelist_file)): (opts.blacklist_file or opts.whitelist_file)):
msg = "You can not use blacklist or whitelist with pdb or no-discover" msg = "You can not use blacklist or whitelist with pdb or no-discover"
print(msg) print(msg)
exit(6) return 6
if ((opts.pdb or opts.no_discover) and (opts.black_regex)): if ((opts.pdb or opts.no_discover) and (opts.black_regex)):
msg = "You can not use black-regex with pdb or no-discover" msg = "You can not use black-regex with pdb or no-discover"
print(msg) print(msg)
exit(7) return 7
if opts.path: if opts.path:
regex = rb.path_to_regex(opts.path) regex = rb.path_to_regex(opts.path)
@ -289,9 +289,13 @@ def main():
regex, regex,
opts.black_regex, opts.black_regex,
opts.print_exclude) opts.print_exclude)
exit(_call_testr_with_list(opts, list_of_tests, others)) return (_call_testr_with_list(opts, list_of_tests, others))
else: else:
exit(_select_and_call_runner(opts, regex, others)) return (_select_and_call_runner(opts, regex, others))
def main():
exit(ostestr(sys.argv[1:]))
if __name__ == '__main__': if __name__ == '__main__':
main() main()