mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-26 19:00:05 +08:00
add HttpRunner class as interface
This commit is contained in:
@@ -7,35 +7,12 @@ from collections import OrderedDict
|
||||
|
||||
from httprunner import __version__ as hrun_version
|
||||
from httprunner import logger
|
||||
from httprunner.exception import TestcaseNotFound
|
||||
from httprunner.task import Result, TaskSuite
|
||||
from httprunner.task import HttpRunner
|
||||
from httprunner.utils import create_scaffold, print_output, string_type
|
||||
from pyunitreport import __version__ as pyu_version
|
||||
from pyunitreport import HTMLTestRunner
|
||||
|
||||
|
||||
def run_suite_path(path, mapping=None, runner=None):
|
||||
""" run suite with YAML/JSON file path
|
||||
@params:
|
||||
- path: testset path
|
||||
- mapping: passed in variables mapping, it will override variables in config block
|
||||
- runner: HTMLTestRunner() or TextTestRunner()
|
||||
"""
|
||||
try:
|
||||
mapping = mapping or {}
|
||||
task_suite = TaskSuite(path, mapping)
|
||||
except TestcaseNotFound:
|
||||
sys.exit(1)
|
||||
|
||||
test_runner = runner or unittest.TextTestRunner()
|
||||
result = test_runner.run(task_suite)
|
||||
|
||||
output = {}
|
||||
for task in task_suite.tasks:
|
||||
output.update(task.output)
|
||||
|
||||
return Result(result, output)
|
||||
|
||||
def main_hrun():
|
||||
""" API test: parse command line options and run commands.
|
||||
"""
|
||||
@@ -76,7 +53,7 @@ def main_hrun():
|
||||
"failfast": args.failfast
|
||||
}
|
||||
test_runner = HTMLTestRunner(**kwargs)
|
||||
result = run_suite_path(args.testset_paths, {}, test_runner)
|
||||
result = HttpRunner(args.testset_paths, test_runner).run()
|
||||
print_output(result.output)
|
||||
|
||||
return 0 if result.success else 1
|
||||
|
||||
Reference in New Issue
Block a user