mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-06 00:09:37 +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)
|
filename = os.path.basename(path)
|
||||||
if filename[0] in string.digits:
|
if filename[0] in string.digits:
|
||||||
path = os.path.join(
|
path = os.path.join(os.path.dirname(path), f"T{filename}")
|
||||||
os.path.dirname(path),
|
|
||||||
f"T{filename}"
|
|
||||||
)
|
|
||||||
|
|
||||||
return path
|
return path
|
||||||
|
|
||||||
@@ -90,6 +87,17 @@ def __ensure_cwd_relative(path: Text) -> Text:
|
|||||||
return path
|
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]:
|
def convert_testcase_path(testcase_path: Text) -> Tuple[Text, Text]:
|
||||||
"""convert single YAML/JSON testcase path to python file"""
|
"""convert single YAML/JSON testcase path to python file"""
|
||||||
if os.path.isdir(testcase_path):
|
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:
|
with open(testcase_python_path, "w", encoding="utf-8") as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
|
__ensure_testcase_module(testcase_python_path)
|
||||||
|
|
||||||
logger.info(f"generated testcase: {testcase_python_path}")
|
logger.info(f"generated testcase: {testcase_python_path}")
|
||||||
make_files_cache_set.add(__ensure_cwd_relative(testcase_python_path))
|
make_files_cache_set.add(__ensure_cwd_relative(testcase_python_path))
|
||||||
|
|
||||||
|
|||||||
@@ -31,13 +31,13 @@ class TestLoader(unittest.TestCase):
|
|||||||
self.assertIn(
|
self.assertIn(
|
||||||
"""
|
"""
|
||||||
from examples.postman_echo.request_methods.request_with_functions_test import (
|
from examples.postman_echo.request_methods.request_with_functions_test import (
|
||||||
TestCaseRequestWithFunctions,
|
TestCaseRequestWithFunctions as RequestWithFunctions,
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
content,
|
content,
|
||||||
)
|
)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
'"testcase": TestCaseRequestWithFunctions,', content,
|
'"testcase": RequestWithFunctions,', content,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_make_testcase_folder(self):
|
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",
|
"/path/to 2/mubu_login_test.py",
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
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(
|
self.assertEqual(
|
||||||
convert_testcase_path("mubu login.yml")[0], "mubu_login_test.py"
|
convert_testcase_path("mubu login.yml")[0], "mubu_login_test.py"
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
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(
|
self.assertEqual(
|
||||||
convert_testcase_path("/path/to 2/mubu-login.yml")[0],
|
convert_testcase_path("/path/to 2/mubu-login.yml")[0],
|
||||||
"/path/to 2/mubu_login_test.py",
|
"/path/to 2/mubu_login_test.py",
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
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(
|
self.assertEqual(
|
||||||
convert_testcase_path("/path/to 2/幕布login.yml")[0],
|
convert_testcase_path("/path/to 2/幕布login.yml")[0],
|
||||||
"/path/to 2/幕布login_test.py",
|
"/path/to 2/幕布login_test.py",
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(convert_testcase_path("/path/to/幕布login.yml")[1], "幕布Login")
|
||||||
convert_testcase_path("/path/to/幕布login.yml")[1], "TestCase幕布Login"
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_make_testsuite(self):
|
def test_make_testsuite(self):
|
||||||
path = ["examples/postman_echo/request_methods/demo_testsuite.yml"]
|
path = ["examples/postman_echo/request_methods/demo_testsuite.yml"]
|
||||||
|
|||||||
@@ -166,7 +166,9 @@ class ResponseObject(object):
|
|||||||
check_item = u_validator["check"]
|
check_item = u_validator["check"]
|
||||||
if "$" in check_item:
|
if "$" in check_item:
|
||||||
# check_item is variable or function
|
# 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:
|
else:
|
||||||
check_value = jmespath.search(check_item, self.resp_obj_meta)
|
check_value = jmespath.search(check_item, self.resp_obj_meta)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user