mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
fix: ensure pytest files are in python module, generate __init__.py on demand
This commit is contained in:
@@ -56,10 +56,7 @@ def __ensure_file_name(path: Text) -> Text:
|
||||
"""
|
||||
filename = os.path.basename(path)
|
||||
if filename[0] in string.digits:
|
||||
path = os.path.join(
|
||||
os.path.dirname(path),
|
||||
f"T{filename}"
|
||||
)
|
||||
path = os.path.join(os.path.dirname(path), f"T{filename}")
|
||||
|
||||
return path
|
||||
|
||||
@@ -90,6 +87,17 @@ def __ensure_cwd_relative(path: Text) -> Text:
|
||||
return path
|
||||
|
||||
|
||||
def __ensure_testcase_module(path: Text) -> NoReturn:
|
||||
""" ensure pytest files are in python module, generate __init__.py on demand
|
||||
"""
|
||||
init_file = os.path.join(os.path.dirname(path), "__init__.py")
|
||||
if os.path.isfile(init_file):
|
||||
return
|
||||
|
||||
with open(init_file, "w", encoding="utf-8") as f:
|
||||
f.write("# NOTICE: Generated By HttpRunner. DO NOT EDIT!")
|
||||
|
||||
|
||||
def convert_testcase_path(testcase_path: Text) -> Tuple[Text, Text]:
|
||||
"""convert single YAML/JSON testcase path to python file"""
|
||||
if os.path.isdir(testcase_path):
|
||||
@@ -194,6 +202,8 @@ def __make_testcase(testcase: Dict, dir_path: Text = None) -> NoReturn:
|
||||
with open(testcase_python_path, "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
|
||||
__ensure_testcase_module(testcase_python_path)
|
||||
|
||||
logger.info(f"generated testcase: {testcase_python_path}")
|
||||
make_files_cache_set.add(__ensure_cwd_relative(testcase_python_path))
|
||||
|
||||
|
||||
@@ -31,13 +31,13 @@ class TestLoader(unittest.TestCase):
|
||||
self.assertIn(
|
||||
"""
|
||||
from examples.postman_echo.request_methods.request_with_functions_test import (
|
||||
TestCaseRequestWithFunctions,
|
||||
TestCaseRequestWithFunctions as RequestWithFunctions,
|
||||
)
|
||||
""",
|
||||
content,
|
||||
)
|
||||
self.assertIn(
|
||||
'"testcase": TestCaseRequestWithFunctions,', content,
|
||||
'"testcase": RequestWithFunctions,', content,
|
||||
)
|
||||
|
||||
def test_make_testcase_folder(self):
|
||||
@@ -61,28 +61,26 @@ from examples.postman_echo.request_methods.request_with_functions_test import (
|
||||
"/path/to 2/mubu_login_test.py",
|
||||
)
|
||||
self.assertEqual(
|
||||
convert_testcase_path("/path/to 2/mubu.login.yml")[1], "TestCaseMubuLogin"
|
||||
convert_testcase_path("/path/to 2/mubu.login.yml")[1], "MubuLogin"
|
||||
)
|
||||
self.assertEqual(
|
||||
convert_testcase_path("mubu login.yml")[0], "mubu_login_test.py"
|
||||
)
|
||||
self.assertEqual(
|
||||
convert_testcase_path("/path/to 2/mubu login.yml")[1], "TestCaseMubuLogin"
|
||||
convert_testcase_path("/path/to 2/mubu login.yml")[1], "MubuLogin"
|
||||
)
|
||||
self.assertEqual(
|
||||
convert_testcase_path("/path/to 2/mubu-login.yml")[0],
|
||||
"/path/to 2/mubu_login_test.py",
|
||||
)
|
||||
self.assertEqual(
|
||||
convert_testcase_path("/path/to 2/mubu-login.yml")[1], "TestCaseMubuLogin"
|
||||
convert_testcase_path("/path/to 2/mubu-login.yml")[1], "MubuLogin"
|
||||
)
|
||||
self.assertEqual(
|
||||
convert_testcase_path("/path/to 2/幕布login.yml")[0],
|
||||
"/path/to 2/幕布login_test.py",
|
||||
)
|
||||
self.assertEqual(
|
||||
convert_testcase_path("/path/to/幕布login.yml")[1], "TestCase幕布Login"
|
||||
)
|
||||
self.assertEqual(convert_testcase_path("/path/to/幕布login.yml")[1], "幕布Login")
|
||||
|
||||
def test_make_testsuite(self):
|
||||
path = ["examples/postman_echo/request_methods/demo_testsuite.yml"]
|
||||
|
||||
@@ -166,7 +166,9 @@ class ResponseObject(object):
|
||||
check_item = u_validator["check"]
|
||||
if "$" in check_item:
|
||||
# check_item is variable or function
|
||||
check_value = parse_data(check_item, variables_mapping, functions_mapping)
|
||||
check_value = parse_data(
|
||||
check_item, variables_mapping, functions_mapping
|
||||
)
|
||||
else:
|
||||
check_value = jmespath.search(check_item, self.resp_obj_meta)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user