add test result stat

This commit is contained in:
debugtalk
2018-02-14 21:12:31 +08:00
parent a0ace0ee76
commit be941250f6
3 changed files with 27 additions and 9 deletions

View File

@@ -35,10 +35,7 @@ def run_suite_path(path, mapping=None, runner=None):
for task in task_suite.tasks:
output.update(task.output)
return Result(
result.wasSuccessful(),
output
)
return Result(result, output)
def main_hrun():
""" API test: parse command line options and run commands.

View File

@@ -44,9 +44,6 @@ class ApiTestSuite(unittest.TestSuite):
}
(dict) variables_mapping:
passed in variables mapping, it will override variables in config block
@return (instance) test result of testset
Result(success, output)
"""
def __init__(self, testset, variables_mapping=None, http_client_session=None):
super(ApiTestSuite, self).__init__()
@@ -116,10 +113,32 @@ class TaskSuite(unittest.TestSuite):
class Result(object):
def __init__(self, success, output):
self.success = success
class Stat(object):
def __init__(self, **stat_dict):
for key, value in stat_dict.items():
setattr(self, key, value)
def __init__(self, result, output):
self.success = result.wasSuccessful()
self.stat = self.make_stat(result)
self.output = output
def make_stat(self, result):
total = result.testsRun
failures = len(result.failures)
errors = len(result.errors)
skipped = len(result.skipped)
successes = total - failures - errors - skipped
stat = {
"total": total,
"successes": successes,
"failures": failures,
"errors": errors,
"skipped": skipped
}
return self.Stat(**stat)
class LocustTask(object):
def __init__(self, path, locust_client, mapping=None):

View File

@@ -84,6 +84,8 @@ class TestRunner(ApiServerUnittest):
def test_run_testsets_hardcode(self):
result = run_suite_path(self.testcase_file_path_list)
self.assertTrue(result.success)
self.assertEqual(result.stat.total, 6)
self.assertEqual(result.stat.successes, 6)
def test_run_testset_template_variables(self):
testcase_file_path = os.path.join(