mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-28 17:27:16 +08:00
add test result stat
This commit is contained in:
@@ -35,10 +35,7 @@ def run_suite_path(path, mapping=None, runner=None):
|
|||||||
for task in task_suite.tasks:
|
for task in task_suite.tasks:
|
||||||
output.update(task.output)
|
output.update(task.output)
|
||||||
|
|
||||||
return Result(
|
return Result(result, output)
|
||||||
result.wasSuccessful(),
|
|
||||||
output
|
|
||||||
)
|
|
||||||
|
|
||||||
def main_hrun():
|
def main_hrun():
|
||||||
""" API test: parse command line options and run commands.
|
""" API test: parse command line options and run commands.
|
||||||
|
|||||||
@@ -44,9 +44,6 @@ class ApiTestSuite(unittest.TestSuite):
|
|||||||
}
|
}
|
||||||
(dict) variables_mapping:
|
(dict) variables_mapping:
|
||||||
passed in variables mapping, it will override variables in config block
|
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):
|
def __init__(self, testset, variables_mapping=None, http_client_session=None):
|
||||||
super(ApiTestSuite, self).__init__()
|
super(ApiTestSuite, self).__init__()
|
||||||
@@ -116,10 +113,32 @@ class TaskSuite(unittest.TestSuite):
|
|||||||
|
|
||||||
class Result(object):
|
class Result(object):
|
||||||
|
|
||||||
def __init__(self, success, output):
|
class Stat(object):
|
||||||
self.success = success
|
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
|
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):
|
class LocustTask(object):
|
||||||
|
|
||||||
def __init__(self, path, locust_client, mapping=None):
|
def __init__(self, path, locust_client, mapping=None):
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ class TestRunner(ApiServerUnittest):
|
|||||||
def test_run_testsets_hardcode(self):
|
def test_run_testsets_hardcode(self):
|
||||||
result = run_suite_path(self.testcase_file_path_list)
|
result = run_suite_path(self.testcase_file_path_list)
|
||||||
self.assertTrue(result.success)
|
self.assertTrue(result.success)
|
||||||
|
self.assertEqual(result.stat.total, 6)
|
||||||
|
self.assertEqual(result.stat.successes, 6)
|
||||||
|
|
||||||
def test_run_testset_template_variables(self):
|
def test_run_testset_template_variables(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
|
|||||||
Reference in New Issue
Block a user