mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
refactor: use loader.load_cases to validate test files
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# Release History
|
||||
|
||||
## 2.5.0 (2019-12-30)
|
||||
|
||||
**Changed**
|
||||
|
||||
- refactor: use loader.load_cases to validate test files
|
||||
|
||||
## 2.4.9 (2019-12-29)
|
||||
|
||||
**Added**
|
||||
|
||||
@@ -4,11 +4,11 @@ import sys
|
||||
|
||||
from sentry_sdk import capture_exception
|
||||
|
||||
from httprunner import __description__, __version__
|
||||
from httprunner import __description__, __version__, exceptions
|
||||
from httprunner.api import HttpRunner
|
||||
from httprunner.compat import is_py2
|
||||
from httprunner.loader import validate_test_file
|
||||
from httprunner.logger import color_print
|
||||
from httprunner.loader import load_cases
|
||||
from httprunner.logger import color_print, log_error
|
||||
from httprunner.report import gen_html_report
|
||||
from httprunner.utils import (create_scaffold, get_python2_retire_msg,
|
||||
prettify_json_file)
|
||||
@@ -73,8 +73,17 @@ def main():
|
||||
sys.exit(0)
|
||||
|
||||
if args.validate:
|
||||
validate_test_file(args.validate)
|
||||
for validate_path in args.validate:
|
||||
try:
|
||||
color_print("validate test file: {}".format(validate_path), "GREEN")
|
||||
load_cases(validate_path, args.dot_env_path)
|
||||
except exceptions.MyBaseError as ex:
|
||||
log_error(str(ex))
|
||||
continue
|
||||
|
||||
color_print("done!", "BLUE")
|
||||
sys.exit(0)
|
||||
|
||||
if args.prettify:
|
||||
prettify_json_file(args.prettify)
|
||||
sys.exit(0)
|
||||
|
||||
@@ -8,7 +8,7 @@ HttpRunner loader
|
||||
|
||||
"""
|
||||
|
||||
from httprunner.loader.check import is_testcase_path, is_testcases, validate_test_file
|
||||
from httprunner.loader.check import is_testcase_path, is_testcases
|
||||
from httprunner.loader.locate import get_project_working_directory as get_pwd
|
||||
from httprunner.loader.load import load_csv_file, load_builtin_functions
|
||||
from httprunner.loader.buildup import load_cases, load_project_data
|
||||
@@ -16,7 +16,6 @@ from httprunner.loader.buildup import load_cases, load_project_data
|
||||
__all__ = [
|
||||
"is_testcase_path",
|
||||
"is_testcases",
|
||||
"validate_test_file",
|
||||
"get_pwd",
|
||||
"load_csv_file",
|
||||
"load_builtin_functions",
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import types
|
||||
|
||||
@@ -149,25 +147,6 @@ def check_testcase_format(file_path, content):
|
||||
raise exceptions.FileFormatError(err_msg)
|
||||
|
||||
|
||||
def validate_test_file(file_list):
|
||||
""" validate JSON testcase format
|
||||
"""
|
||||
for test_file in set(file_list):
|
||||
if not test_file.endswith(".json"):
|
||||
logger.log_warning("Only JSON file format can be validated, skip: {}".format(test_file))
|
||||
continue
|
||||
|
||||
logger.color_print("Start to validate JSON file: {}".format(test_file), "GREEN")
|
||||
|
||||
with io.open(test_file) as stream:
|
||||
try:
|
||||
json.load(stream)
|
||||
except ValueError as e:
|
||||
raise SystemExit(e)
|
||||
|
||||
print("OK")
|
||||
|
||||
|
||||
def is_function(item):
|
||||
""" Takes item object, returns True if it is a function.
|
||||
"""
|
||||
|
||||
@@ -22,7 +22,12 @@ def _load_yaml_file(yaml_file):
|
||||
""" load yaml file and check file content format
|
||||
"""
|
||||
with io.open(yaml_file, 'r', encoding='utf-8') as stream:
|
||||
yaml_content = yaml.load(stream)
|
||||
try:
|
||||
yaml_content = yaml.load(stream)
|
||||
except yaml.YAMLError as ex:
|
||||
logger.log_error(str(ex))
|
||||
raise exceptions.FileFormatError
|
||||
|
||||
check_testcase_format(yaml_file, yaml_content)
|
||||
return yaml_content
|
||||
|
||||
|
||||
Reference in New Issue
Block a user