diff options
author | Matthew Treinish <mtreinish@kortar.org> | 2016-01-04 18:29:56 -0500 |
---|---|---|
committer | Matthew Treinish <mtreinish@kortar.org> | 2020-03-14 09:31:08 -0400 |
commit | 0e14d8be6126315c19c40905d75e55b2bfe7ba09 (patch) | |
tree | 3110e217857d6479f416cb873dbb12b2fcdbd65a /python/subunit/_output.py | |
parent | 26d31fa7c34019fad9038addf8114bbb4b656c92 (diff) | |
download | subunit-git-0e14d8be6126315c19c40905d75e55b2bfe7ba09.tar.gz |
Add options to output filter to set timestamps
This commit adds 2 new options to subunit-output, --start-time and
--stop-time, to specify a timestamp for the start and end of a test
in the output.
Diffstat (limited to 'python/subunit/_output.py')
-rw-r--r-- | python/subunit/_output.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/python/subunit/_output.py b/python/subunit/_output.py index aa92646..c598c81 100644 --- a/python/subunit/_output.py +++ b/python/subunit/_output.py @@ -22,6 +22,8 @@ from optparse import ( ) import sys +from dateutil import parser as date_parser + from subunit import make_stream_binary from subunit.iso8601 import UTC from subunit.v2 import StreamResultToBytes @@ -121,6 +123,18 @@ def parse_arguments(args=None, ParserClass=OptionParser): dest="tags", default=[] ) + parser.add_option( + "--start-time", + help="Specify a time for the test to start", + dest="start_time", + default=None + ) + parser.add_option( + "--stop-time", + help="Specify a time for the test to finish executing", + dest="stop_time", + default=None + ) (options, args) = parser.parse_args(args) if options.mimetype and not options.attach_file: @@ -152,6 +166,14 @@ def set_status_cb(option, opt_str, value, parser, status_name): def generate_stream_results(args, output_writer): + if args.start_time: + start_time = date_parser.parse(args.start_time) + else: + start_time = None + if args.stop_time: + stop_time = date_parser.parse(args.stop_time) + else: + stop_time = None output_writer.startTestRun() if args.attach_file: @@ -170,6 +192,7 @@ def generate_stream_results(args, output_writer): write_status = partial(write_status, mime_type=args.mimetype) if args.tags: write_status = partial(write_status, test_tags=set(args.tags)) + timestamp = start_time or create_timestamp() write_status = partial(write_status, timestamp=create_timestamp()) if args.action not in _FINAL_ACTIONS: write_status = partial(write_status, test_status=args.action) @@ -192,7 +215,11 @@ def generate_stream_results(args, output_writer): if is_last_packet: if args.action in _FINAL_ACTIONS: - write_status = partial(write_status, test_status=args.action) + if stop_time: + write_status = partial(write_status, test_status=args.action, + timestamp=stop_time) + else: + write_status = partial(write_status, test_status=args.action) write_status() |