diff --git a/subunit2sql/db/api.py b/subunit2sql/db/api.py index 15f272c..3bc913b 100644 --- a/subunit2sql/db/api.py +++ b/subunit2sql/db/api.py @@ -105,7 +105,7 @@ def update_test(values, test_id, session=None): def create_run(skips=0, fails=0, passes=0, run_time=0, artifacts=None, - session=None): + id=None, session=None): """Create a new run record in the database :param int skips: total number of skiped tests defaults to 0 @@ -114,6 +114,7 @@ def create_run(skips=0, fails=0, passes=0, run_time=0, artifacts=None, :param float run_time: total run timed defaults to 0 :param str artifacts: A link to any artifacts from the test run defaults to None + :param str id: the run id for the new run, needs to be a unique value :param session: optional session object if one isn't provided a new session will be acquired for the duration of this operation @@ -121,6 +122,8 @@ def create_run(skips=0, fails=0, passes=0, run_time=0, artifacts=None, :rtype: subunit2sql.models.Run """ run = models.Run() + if id: + run.id = id run.skips = skips run.fails = fails run.passes = passes diff --git a/subunit2sql/shell.py b/subunit2sql/shell.py index 77ddb6f..8a7510e 100644 --- a/subunit2sql/shell.py +++ b/subunit2sql/shell.py @@ -32,7 +32,10 @@ SHELL_OPTS = [ cfg.DictOpt('run_meta', short='r', default=None, help='Dict of metadata about the run(s)'), cfg.StrOpt('artifacts', short='a', default=None, - help='Location of run artifacts') + help='Location of run artifacts'), + cfg.StrOpt('run_id', short='i', default=None, + help='Run id to use for the specified subunit stream, can only' + ' be used if a single stream is provided') ] _version_ = version.VersionInfo('subunit2sql').version_string() @@ -106,7 +109,7 @@ def process_results(results): totals = get_run_totals(results) db_run = api.create_run(totals['skips'], totals['fails'], totals['success'], run_time, CONF.artifacts, - session=session) + id=CONF.run_id, session=session) if CONF.run_meta: api.add_run_metadata(CONF.run_meta, db_run.id, session) for test in results: @@ -146,6 +149,9 @@ def main(): cli_opts() parse_args(sys.argv) if CONF.subunit_files: + if len(CONF.subunit_files) > 1 and CONF.run_id: + print("You can not specify a run id for adding more than 1 stream") + return 3 streams = [subunit.ReadSubunit(open(s, 'r')) for s in CONF.subunit_files] else: