update loader.load

This commit is contained in:
debugtalk
2018-08-09 13:20:20 +08:00
parent ad916c032d
commit a4fc8888c7
2 changed files with 30 additions and 22 deletions
-3
View File
@@ -745,8 +745,5 @@ def load(path):
list: testcases list list: testcases list
""" """
if validator.is_testcases(path):
return path
_load_test_dependencies() _load_test_dependencies()
return load_testcases(path) return load_testcases(path)
+30 -19
View File
@@ -4,7 +4,8 @@ import copy
import sys import sys
import unittest import unittest
from httprunner import context, exceptions, loader, logger, runner, utils from httprunner import (context, exceptions, loader, logger, runner, utils,
validator)
from httprunner.compat import is_py3 from httprunner.compat import is_py3
from httprunner.report import (HtmlTestResult, get_platform, get_summary, from httprunner.report import (HtmlTestResult, get_platform, get_summary,
render_html_report) render_html_report)
@@ -159,10 +160,12 @@ class TestSuite(unittest.TestSuite):
return outputs return outputs
def init_test_suites(path_or_testsets, mapping=None, http_client_session=None): def init_test_suites(path_or_testcases, mapping=None, http_client_session=None):
""" initialize TestSuite list with testset path or testset dict """ initialize TestSuite list with testcase path or testcase(s).
@params
testsets (dict/list): testset or list of testset Args:
path_or_testcases (str/dict/list): testcase file path or testcase dict or testcases list
testset_dict testset_dict
or or
[ [
@@ -174,23 +177,31 @@ def init_test_suites(path_or_testsets, mapping=None, http_client_session=None):
"testcases": [testcase11, testcase12] "testcases": [testcase11, testcase12]
} }
] ]
mapping (dict):
passed in variables mapping, it will override variables in config block mapping (dict): passed in variables mapping, it will override variables in config block.
http_client_session (instance): requests.Session(), or locusts.client.Session() instance.
Returns:
list: TestSuite() instance list.
""" """
testsets = loader.load(path_or_testsets) if validator.is_testcases(path_or_testcases):
testcases = path_or_testcases
else:
testcases = loader.load(path_or_testcases)
# TODO: move comparator uniform here # TODO: move comparator uniform here
mapping = mapping or {} mapping = mapping or {}
if not testsets: if not testcases:
raise exceptions.TestcaseNotFound raise exceptions.TestcaseNotFound
if isinstance(testsets, dict): if isinstance(testcases, dict):
testsets = [testsets] testcases = [testcases]
test_suite_list = [] test_suite_list = []
for testset in testsets: for testcase in testcases:
test_suite = TestSuite(testset, mapping, http_client_session) test_suite = TestSuite(testcase, mapping, http_client_session)
test_suite_list.append(test_suite) test_suite_list.append(test_suite)
return test_suite_list return test_suite_list
@@ -212,9 +223,9 @@ class HttpRunner(object):
kwargs.setdefault("resultclass", HtmlTestResult) kwargs.setdefault("resultclass", HtmlTestResult)
self.runner = unittest.TextTestRunner(**kwargs) self.runner = unittest.TextTestRunner(**kwargs)
def run(self, path_or_testsets, mapping=None): def run(self, path_or_testcases, mapping=None):
""" start to run test with varaibles mapping """ start to run test with varaibles mapping
@param path_or_testsets: YAML/JSON testset file path or testset list @param path_or_testcases: YAML/JSON testset file path or testset list
path: path could be in several type path: path could be in several type
- absolute/relative file path - absolute/relative file path
- absolute/relative folder path - absolute/relative folder path
@@ -230,9 +241,9 @@ class HttpRunner(object):
if mapping specified, it will override variables in config block if mapping specified, it will override variables in config block
""" """
try: try:
test_suite_list = init_test_suites(path_or_testsets, mapping) test_suite_list = init_test_suites(path_or_testcases, mapping)
except exceptions.TestcaseNotFound: except exceptions.TestcaseNotFound:
logger.log_error("Testcases not found in {}".format(path_or_testsets)) logger.log_error("Testcases not found in {}".format(path_or_testcases))
sys.exit(1) sys.exit(1)
self.summary = { self.summary = {
@@ -288,8 +299,8 @@ class HttpRunner(object):
class LocustTask(object): class LocustTask(object):
def __init__(self, path_or_testsets, locust_client, mapping=None): def __init__(self, path_or_testcases, locust_client, mapping=None):
self.test_suite_list = init_test_suites(path_or_testsets, mapping, locust_client) self.test_suite_list = init_test_suites(path_or_testcases, mapping, locust_client)
def run(self): def run(self):
for test_suite in self.test_suite_list: for test_suite in self.test_suite_list: