Add support to ostestr to use subunit-trace color
This commit adds a new flag to the ostestr cli, --color, which is a passthrough option to subunit-trace to enabled colorized output. Change-Id: Ic38e008982d8f5bca78c52f51c69b5333744ecbc
This commit is contained in:
parent
2fb3b5ecff
commit
2cb71893d1
@ -58,6 +58,8 @@ def get_parser(args):
|
|||||||
'this is mutually exclusive with --pretty')
|
'this is mutually exclusive with --pretty')
|
||||||
parser.add_argument('--list', '-l', action='store_true',
|
parser.add_argument('--list', '-l', action='store_true',
|
||||||
help='List all the tests which will be run.')
|
help='List all the tests which will be run.')
|
||||||
|
parser.add_argument('--color', action='store_true',
|
||||||
|
help='Use color in the pretty output')
|
||||||
slowest = parser.add_mutually_exclusive_group()
|
slowest = parser.add_mutually_exclusive_group()
|
||||||
slowest.add_argument('--slowest', dest='slowest', action='store_true',
|
slowest.add_argument('--slowest', dest='slowest', action='store_true',
|
||||||
help="after the test run print the slowest tests")
|
help="after the test run print the slowest tests")
|
||||||
@ -166,7 +168,7 @@ def construct_regex(blacklist_file, whitelist_file, regex, print_exclude):
|
|||||||
|
|
||||||
|
|
||||||
def call_testr(regex, subunit, pretty, list_tests, slowest, parallel, concur,
|
def call_testr(regex, subunit, pretty, list_tests, slowest, parallel, concur,
|
||||||
until_failure):
|
until_failure, color):
|
||||||
if parallel:
|
if parallel:
|
||||||
cmd = ['testr', 'run', '--parallel']
|
cmd = ['testr', 'run', '--parallel']
|
||||||
if concur:
|
if concur:
|
||||||
@ -181,6 +183,12 @@ def call_testr(regex, subunit, pretty, list_tests, slowest, parallel, concur,
|
|||||||
cmd.append('--until-failure')
|
cmd.append('--until-failure')
|
||||||
cmd.append(regex)
|
cmd.append(regex)
|
||||||
env = copy.deepcopy(os.environ)
|
env = copy.deepcopy(os.environ)
|
||||||
|
|
||||||
|
if pretty:
|
||||||
|
subunit_trace_cmd = ['subunit-trace', '--no-failure-debug', '-f']
|
||||||
|
if color:
|
||||||
|
subunit_trace_cmd.append('--color')
|
||||||
|
|
||||||
# This workaround is necessary because of lp bug 1411804 it's super hacky
|
# This workaround is necessary because of lp bug 1411804 it's super hacky
|
||||||
# and makes tons of unfounded assumptions, but it works for the most part
|
# and makes tons of unfounded assumptions, but it works for the most part
|
||||||
if (subunit or pretty) and until_failure:
|
if (subunit or pretty) and until_failure:
|
||||||
@ -198,9 +206,9 @@ def call_testr(regex, subunit, pretty, list_tests, slowest, parallel, concur,
|
|||||||
if pretty:
|
if pretty:
|
||||||
cmd = ['python', '-m', 'subunit.run', test]
|
cmd = ['python', '-m', 'subunit.run', test]
|
||||||
ps = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE)
|
ps = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE)
|
||||||
proc = subprocess.Popen(['subunit-trace',
|
subunit_trace_cmd.append('--no-summary')
|
||||||
'--no-failure-debug', '-f',
|
proc = subprocess.Popen(subunit_trace_cmd,
|
||||||
'--no-summary'], env=env,
|
env=env,
|
||||||
stdin=ps.stdout)
|
stdin=ps.stdout)
|
||||||
ps.stdout.close()
|
ps.stdout.close()
|
||||||
proc.communicate()
|
proc.communicate()
|
||||||
@ -223,7 +231,7 @@ def call_testr(regex, subunit, pretty, list_tests, slowest, parallel, concur,
|
|||||||
# 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:
|
||||||
ps = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE)
|
ps = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE)
|
||||||
proc = subprocess.Popen(['subunit-trace', '--no-failure-debug', '-f'],
|
proc = subprocess.Popen(subunit_trace_cmd,
|
||||||
env=env, stdin=ps.stdout)
|
env=env, stdin=ps.stdout)
|
||||||
ps.stdout.close()
|
ps.stdout.close()
|
||||||
else:
|
else:
|
||||||
@ -261,7 +269,7 @@ def _select_and_call_runner(opts, exclude_regex):
|
|||||||
if not opts.no_discover and not opts.pdb:
|
if not opts.no_discover and not opts.pdb:
|
||||||
ec = call_testr(exclude_regex, opts.subunit, opts.pretty, opts.list,
|
ec = call_testr(exclude_regex, opts.subunit, opts.pretty, opts.list,
|
||||||
opts.slowest, opts.parallel, opts.concurrency,
|
opts.slowest, opts.parallel, opts.concurrency,
|
||||||
opts.until_failure)
|
opts.until_failure, opts.color)
|
||||||
else:
|
else:
|
||||||
test_to_run = opts.no_discover or opts.pdb
|
test_to_run = opts.no_discover or opts.pdb
|
||||||
if test_to_run.find('/') != -1:
|
if test_to_run.find('/') != -1:
|
||||||
|
Loading…
Reference in New Issue
Block a user