mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
fix: compatibility with different path separators of Linux and Windows
This commit is contained in:
@@ -348,3 +348,15 @@ def session_fixture(request):
|
|||||||
f.write(conftest_content)
|
f.write(conftest_content)
|
||||||
|
|
||||||
logger.info("generated conftest.py to generate summary.json")
|
logger.info("generated conftest.py to generate summary.json")
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_path_sep(path: Text) -> Text:
|
||||||
|
""" ensure compatibility with different path separators of Linux and Windows
|
||||||
|
"""
|
||||||
|
if "/" in path:
|
||||||
|
path = os.sep.join(path.split("/"))
|
||||||
|
|
||||||
|
if "\\" in path:
|
||||||
|
path = os.sep.join(path.split("\\"))
|
||||||
|
|
||||||
|
return path
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import sys
|
|||||||
from loguru import logger
|
from loguru import logger
|
||||||
from sentry_sdk import capture_message
|
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
|
||||||
|
|
||||||
|
|
||||||
@@ -59,6 +60,7 @@ def main_har2case(args):
|
|||||||
logger.error("HAR file not specified.")
|
logger.error("HAR file not specified.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
har_source_file = ensure_path_sep(har_source_file)
|
||||||
if not os.path.isfile(har_source_file):
|
if not os.path.isfile(har_source_file):
|
||||||
logger.error(f"HAR file not exists: {har_source_file}")
|
logger.error(f"HAR file not exists: {har_source_file}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from httprunner.compat import (
|
|||||||
ensure_testcase_v3_api,
|
ensure_testcase_v3_api,
|
||||||
ensure_testcase_v3,
|
ensure_testcase_v3,
|
||||||
convert_variables,
|
convert_variables,
|
||||||
|
ensure_path_sep,
|
||||||
)
|
)
|
||||||
from httprunner.loader import (
|
from httprunner.loader import (
|
||||||
load_folder_files,
|
load_folder_files,
|
||||||
@@ -498,6 +499,7 @@ def main_make(tests_paths: List[Text]) -> List[Text]:
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
for tests_path in tests_paths:
|
for tests_path in tests_paths:
|
||||||
|
tests_path = ensure_path_sep(tests_path)
|
||||||
if not os.path.isabs(tests_path):
|
if not os.path.isabs(tests_path):
|
||||||
tests_path = os.path.join(os.getcwd(), tests_path)
|
tests_path = os.path.join(os.getcwd(), tests_path)
|
||||||
|
|
||||||
|
|||||||
+17
-1
@@ -2,7 +2,7 @@ import os
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from httprunner import compat, exceptions, loader
|
from httprunner import compat, exceptions, loader
|
||||||
from httprunner.compat import convert_variables
|
from httprunner.compat import convert_variables, ensure_path_sep
|
||||||
|
|
||||||
|
|
||||||
class TestCompat(unittest.TestCase):
|
class TestCompat(unittest.TestCase):
|
||||||
@@ -213,3 +213,19 @@ class TestCompat(unittest.TestCase):
|
|||||||
"--self-contained-html",
|
"--self-contained-html",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_ensure_file_path(self):
|
||||||
|
self.assertEqual(
|
||||||
|
ensure_path_sep("demo\\test.yml"), os.sep.join(["demo", "test.yml"])
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
ensure_path_sep(os.path.join(os.getcwd(), "demo\\test.yml")),
|
||||||
|
os.path.join(os.getcwd(), os.sep.join(["demo", "test.yml"])),
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
ensure_path_sep("demo/test.yml"), os.sep.join(["demo", "test.yml"])
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
ensure_path_sep(os.path.join(os.getcwd(), "demo/test.yml")),
|
||||||
|
os.path.join(os.getcwd(), os.sep.join(["demo", "test.yml"])),
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user