mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
fix: path handling error when har2case har file and cwd != ProjectRootDir
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
**Fixed**
|
||||
|
||||
- change: do not raise error if failed to get client/server address info
|
||||
- fix: path handling error when har2case har file and cwd != ProjectRootDir
|
||||
|
||||
## 3.0.13 (2020-06-17)
|
||||
|
||||
|
||||
@@ -8,14 +8,9 @@ Usage:
|
||||
$ hrun har2case demo.har -2y
|
||||
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
from loguru import logger
|
||||
from sentry_sdk import capture_message
|
||||
|
||||
from httprunner.compat import ensure_path_sep
|
||||
from httprunner.ext.har2case.core import HarParser
|
||||
from sentry_sdk import capture_message
|
||||
|
||||
|
||||
def init_har2case_parser(subparsers):
|
||||
@@ -56,14 +51,6 @@ def init_har2case_parser(subparsers):
|
||||
|
||||
def main_har2case(args):
|
||||
har_source_file = args.har_source_file
|
||||
if not har_source_file or not har_source_file.endswith(".har"):
|
||||
logger.error("HAR file not specified.")
|
||||
sys.exit(1)
|
||||
|
||||
har_source_file = ensure_path_sep(har_source_file)
|
||||
if not os.path.isfile(har_source_file):
|
||||
logger.error(f"HAR file not exists: {har_source_file}")
|
||||
sys.exit(1)
|
||||
|
||||
if args.to_yaml:
|
||||
output_file_type = "YAML"
|
||||
|
||||
@@ -3,7 +3,9 @@ import json
|
||||
import os
|
||||
import sys
|
||||
import urllib.parse as urlparse
|
||||
from typing import Text
|
||||
|
||||
from httprunner.compat import ensure_path_sep
|
||||
from loguru import logger
|
||||
from sentry_sdk import capture_exception
|
||||
|
||||
@@ -16,9 +18,26 @@ except ImportError:
|
||||
JSONDecodeError = ValueError
|
||||
|
||||
|
||||
def ensure_file_path(path: Text) -> Text:
|
||||
|
||||
if not path or not path.endswith(".har"):
|
||||
logger.error("HAR file not specified.")
|
||||
sys.exit(1)
|
||||
|
||||
path = ensure_path_sep(path)
|
||||
if not os.path.isfile(path):
|
||||
logger.error(f"HAR file not exists: {path}")
|
||||
sys.exit(1)
|
||||
|
||||
if not os.path.isabs(path):
|
||||
path = os.path.join(os.getcwd(), path)
|
||||
|
||||
return path
|
||||
|
||||
|
||||
class HarParser(object):
|
||||
def __init__(self, har_file_path, filter_str=None, exclude_str=None):
|
||||
self.har_file_path = har_file_path
|
||||
self.har_file_path = ensure_file_path(har_file_path)
|
||||
self.filter_str = filter_str
|
||||
self.exclude_str = exclude_str or ""
|
||||
|
||||
@@ -346,7 +365,7 @@ class HarParser(object):
|
||||
utils.dump_yaml(testcase, output_testcase_file)
|
||||
else:
|
||||
# default to generate pytest file
|
||||
testcase["config"]["path"] = self.har_file_path
|
||||
testcase["config"]["path"] = os.path.join(os.getcwd(), self.har_file_path)
|
||||
output_testcase_file = make_testcase(testcase)
|
||||
format_pytest_with_black(output_testcase_file)
|
||||
|
||||
|
||||
@@ -80,7 +80,8 @@ def __ensure_absolute(path: Text) -> Text:
|
||||
absolute_path = os.path.join(project_meta.RootDir, path)
|
||||
|
||||
if not os.path.isfile(absolute_path):
|
||||
raise exceptions.ParamsError(f"Invalid testcase file path: {absolute_path}")
|
||||
logger.error(f"Invalid testcase file path: {absolute_path}")
|
||||
sys.exit(1)
|
||||
|
||||
return absolute_path
|
||||
|
||||
|
||||
Reference in New Issue
Block a user