diff --git a/subunit2sql/db/models.py b/subunit2sql/db/models.py index 44ff961..439b737 100644 --- a/subunit2sql/db/models.py +++ b/subunit2sql/db/models.py @@ -65,7 +65,7 @@ class Run(BASE, SubunitBase): skips = sa.Column(sa.Integer()) fails = sa.Column(sa.Integer()) passes = sa.Column(sa.Integer()) - run_time = sa.Column(sa.Integer()) + run_time = sa.Column(sa.Float()) artifacts = sa.Column(sa.Text()) diff --git a/subunit2sql/migrations/versions/1f92cfe8a6d3_create_runs_table.py b/subunit2sql/migrations/versions/1f92cfe8a6d3_create_runs_table.py index f5477bb..19a0c3e 100644 --- a/subunit2sql/migrations/versions/1f92cfe8a6d3_create_runs_table.py +++ b/subunit2sql/migrations/versions/1f92cfe8a6d3_create_runs_table.py @@ -35,7 +35,7 @@ def upgrade(): sa.Column('skips', sa.Integer()), sa.Column('fails', sa.Integer()), sa.Column('passes', sa.Integer()), - sa.Column('run_time', sa.Integer()), + sa.Column('run_time', sa.Float()), sa.Column('artifacts', sa.Text()), mysql_engine=True) diff --git a/subunit2sql/read_subunit.py b/subunit2sql/read_subunit.py index 5ed5219..c31889c 100644 --- a/subunit2sql/read_subunit.py +++ b/subunit2sql/read_subunit.py @@ -17,6 +17,8 @@ import functools import subunit import testtools +DAY_SECONDS = 60 * 60 * 24 + class ReadSubunit(object): @@ -36,6 +38,7 @@ class ReadSubunit(object): self.stream.run(self.result) finally: self.result.stopTestRun() + self.results['run_time'] = self.run_time() return self.results def parse_outcome(self, test): @@ -80,3 +83,19 @@ class ReadSubunit(object): newname += name[tags_end + 1:] name = newname return name + + def get_duration(self, start, end): + if not start or not end: + duration = '' + else: + delta = end - start + duration = '%d.%06ds' % ( + delta.days * DAY_SECONDS + delta.seconds, delta.microseconds) + return duration + + def run_time(self): + runtime = 0.0 + for name, data in self.results.items(): + runtime += float(self.get_duration(data['start_time'], + data['end_time']).strip('s')) + return runtime diff --git a/subunit2sql/shell.py b/subunit2sql/shell.py index 92a47bc..9fe2b9f 100644 --- a/subunit2sql/shell.py +++ b/subunit2sql/shell.py @@ -51,7 +51,7 @@ def parse_args(argv, default_config_files=None): def process_results(results): session = api.get_session() - db_run = api.create_run() + db_run = api.create_run(run_time=results.pop('run_time')) for test in results: db_test = api.get_test_by_test_id(test, session) if not db_test: