Fix handling of xfail and uxsuccess results in subunit2sql cli

This commit fixes an issue with the subunit2sql cli (for importing
subunit streams to the DB) when the subunit stream has a test_run with
an xfail or unxsuccess status. Previously we didn't handle these
statuses at all and we'd raise an exception because they weren't known.
This fixes this by treating xfail the same as success and uxsuccess the
same as failure.

Change-Id: Ib84eb5e4b2da4847e86ff24c8bc5ba19a0df5b37
This commit is contained in:
Matthew Treinish 2018-12-17 19:13:44 -05:00
parent 96940dd287
commit 35793871f3
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177
2 changed files with 38 additions and 2 deletions

View File

@ -106,10 +106,10 @@ def running_avg(test, values, result):
def increment_counts(test, results): def increment_counts(test, results):
test_values = {'run_count': test.run_count + 1} test_values = {'run_count': test.run_count + 1}
status = results.get('status') status = results.get('status')
if status == 'success': if status in ['success', 'xfail']:
test_values['success'] = test.success + 1 test_values['success'] = test.success + 1
test_values = running_avg(test, test_values, results) test_values = running_avg(test, test_values, results)
elif status == 'fail': elif status in ['fail', 'uxsuccess']:
test_values['failure'] = test.failure + 1 test_values['failure'] = test.failure + 1
elif status == 'skip': elif status == 'skip':
test_values = {} test_values = {}

View File

@ -138,6 +138,42 @@ class TestShell(base.TestCase):
self.assertRaises(exceptions.UnknownStatus, self.assertRaises(exceptions.UnknownStatus,
shell.increment_counts, fake_test, fake_result) shell.increment_counts, fake_test, fake_result)
def test_increment_counts_success_xfail(self):
fake_test = mock.MagicMock()
fake_test.run_count = 15
fake_test.success = 5
fake_test.run_time = 45.0
fake_result = {
'status': 'xfail',
'start_time': datetime.datetime(1914, 6, 28, 10, 45, 0),
'end_time': datetime.datetime(1914, 6, 28, 10, 45, 50),
}
values = shell.increment_counts(fake_test, fake_result)
# Check to ensure counts incremented properly
self.assertEqual(values['run_count'], 16)
self.assertEqual(values['success'], 6)
# Ensure run_time is updated on success
expected_avg = ((5 * 45.0) + 50) / 6
self.assertEqual(values['run_time'], expected_avg)
def test_increment_counts_uxsuccess(self):
fake_test = mock.MagicMock()
fake_test.run_count = 15
fake_test.success = 5
fake_test.failure = 10
fake_test.run_time = 45.0
fake_result = {
'status': 'uxsuccess',
'start_time': datetime.datetime(1914, 6, 28, 10, 45, 0),
'end_time': datetime.datetime(1914, 6, 28, 10, 45, 50),
}
values = shell.increment_counts(fake_test, fake_result)
# Check to ensure counts incremented properly
self.assertEqual(values['run_count'], 16)
self.assertEqual(values['failure'], 11)
# Avg runtime should only be updated on success
self.assertNotIn('run_time', values)
class TestMain(base.TestCase): class TestMain(base.TestCase):
def setUp(self): def setUp(self):