diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0a5d43ff..7580ec70 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,6 +5,7 @@ **Fixed** - fix: extract response cookies +- fix: handle errors when no valid testcases generated ## 3.0.3 (2020-05-17) diff --git a/httprunner/cli.py b/httprunner/cli.py index 34d9d0ff..10bbda97 100644 --- a/httprunner/cli.py +++ b/httprunner/cli.py @@ -3,6 +3,7 @@ import os import sys import pytest +from loguru import logger from httprunner import __description__, __version__, exceptions from httprunner.ext.har2case import init_har2case_parser, main_har2case @@ -33,7 +34,10 @@ def main_run(extra_args): # has not specified any testcase path raise exceptions.ParamsError("Missed testcase path") - main_make(tests_path_list) + testcase_path_list = main_make(tests_path_list) + if not testcase_path_list: + logger.error("No valid testcases found, exit 1.") + sys.exit(1) if "-s" not in extra_args: extra_args.insert(0, "-s") diff --git a/httprunner/ext/make/__init__.py b/httprunner/ext/make/__init__.py index 7da40807..48c4aeaf 100644 --- a/httprunner/ext/make/__init__.py +++ b/httprunner/ext/make/__init__.py @@ -89,7 +89,7 @@ def format_with_black(tests_path: Text): logger.error(ex) -def make(tests_path: Text) -> List: +def __make(tests_path: Text) -> List: testcases = [] if os.path.isdir(tests_path): files_list = load_folder_files(tests_path) @@ -106,6 +106,10 @@ def make(tests_path: Text) -> List: continue testcase_path_list.append(testcase_path) + if not testcase_path_list: + logger.warning(f"No valid testcase generated on {tests_path}") + return [] + format_with_black(tests_path) return testcase_path_list @@ -113,7 +117,7 @@ def make(tests_path: Text) -> List: def main_make(tests_paths: List[Text]) -> List: testcase_path_list = [] for tests_path in tests_paths: - testcase_path_list.extend(make(tests_path)) + testcase_path_list.extend(__make(tests_path)) return testcase_path_list