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