From c9ed952a44e91a03d522b90061d337c528b42e79 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 2 Nov 2017 15:08:59 +0800 Subject: [PATCH] fix: run testcases by folder path --- ate/cli.py | 5 +---- ate/exception.py | 14 ++++++++++---- ate/task.py | 2 +- ate/testcase.py | 13 +++++++++---- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/ate/cli.py b/ate/cli.py index 31494346..74930d8b 100644 --- a/ate/cli.py +++ b/ate/cli.py @@ -65,10 +65,7 @@ def main_ate(): try: task_suite = TaskSuite(testset_path) - except exception.FileFormatError: - success = False - continue - except exception.FileNotFoundError: + except exception.TestcaseNotFound: success = False continue diff --git a/ate/exception.py b/ate/exception.py index 70461d59..f9c13951 100644 --- a/ate/exception.py +++ b/ate/exception.py @@ -29,14 +29,20 @@ class ParseResponseError(MyBaseError): class ValidationError(MyBaseError): pass -class FunctionNotFound(NameError): +class NotFoundError(MyBaseError): pass -class VariableNotFound(NameError): +class FunctionNotFound(NotFoundError): pass -class ApiNotFound(NameError): +class VariableNotFound(NotFoundError): pass -class SuiteNotFound(NameError): +class ApiNotFound(NotFoundError): + pass + +class SuiteNotFound(NotFoundError): + pass + +class TestcaseNotFound(NotFoundError): pass diff --git a/ate/task.py b/ate/task.py index 438059a1..ec5241ea 100644 --- a/ate/task.py +++ b/ate/task.py @@ -52,7 +52,7 @@ class TaskSuite(unittest.TestSuite): self.suite_list = [] testsets = testcase.load_testcases_by_path(testcase_path) if not testsets: - raise exception.FileNotFoundError + raise exception.TestcaseNotFound for testset in testsets: suite = ApiTestSuite(testset) diff --git a/ate/testcase.py b/ate/testcase.py index 9f714faa..437bcdd5 100644 --- a/ate/testcase.py +++ b/ate/testcase.py @@ -49,6 +49,8 @@ def _load_file(testcase_file_path): return _load_yaml_file(testcase_file_path) else: # '' or other suffix + err_msg = "file is not in YAML/JSON format: {}".format(testcase_file_path) + logging.warning(err_msg) return [] def extract_variables(content): @@ -194,10 +196,13 @@ def load_testcases_by_path(path): testcases_list = load_testcases_by_path(files_list) elif os.path.isfile(path): - testset = load_test_file(path) - if testset["testcases"] or testset["api"]: - testcases_list = [testset] - else: + try: + testset = load_test_file(path) + if testset["testcases"] or testset["api"]: + testcases_list = [testset] + else: + testcases_list = [] + except exception.FileFormatError: testcases_list = [] else: