diff --git a/httprunner/cli.py b/httprunner/cli.py index c4ebaf73..fcc368cc 100644 --- a/httprunner/cli.py +++ b/httprunner/cli.py @@ -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. diff --git a/httprunner/task.py b/httprunner/task.py index fbd2957e..54d21c4f 100644 --- a/httprunner/task.py +++ b/httprunner/task.py @@ -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): diff --git a/tests/test_runner.py b/tests/test_runner.py index ed362751..f8ac6492 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -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(