mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
feat: hrun supports run pytest files
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
**Added**
|
**Added**
|
||||||
|
|
||||||
- feat: make pytest files in chain style
|
- feat: make pytest files in chain style
|
||||||
|
- feat: `hrun` supports run pytest files
|
||||||
|
|
||||||
**Fixed**
|
**Fixed**
|
||||||
|
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ def load_csv_file(csv_file: Text) -> List[Dict]:
|
|||||||
|
|
||||||
|
|
||||||
def load_folder_files(folder_path: Text, recursive: bool = True) -> List:
|
def load_folder_files(folder_path: Text, recursive: bool = True) -> List:
|
||||||
""" load folder path, return all files endswith yml/yaml/json in list.
|
""" load folder path, return all files endswith .yml/.yaml/.json/_test.py in list.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
folder_path (str): specified folder path to load
|
folder_path (str): specified folder path to load
|
||||||
@@ -219,7 +219,7 @@ def load_folder_files(folder_path: Text, recursive: bool = True) -> List:
|
|||||||
filenames_list = []
|
filenames_list = []
|
||||||
|
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
if not filename.endswith((".yml", ".yaml", ".json")):
|
if not filename.lower().endswith((".yml", ".yaml", ".json", "_test.py")):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
filenames_list.append(filename)
|
filenames_list.append(filename)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ from httprunner.response import uniform_validator
|
|||||||
""" cache converted pytest files, avoid duplicate making
|
""" cache converted pytest files, avoid duplicate making
|
||||||
"""
|
"""
|
||||||
make_files_cache_set: Set = set()
|
make_files_cache_set: Set = set()
|
||||||
|
pytest_files_set: Set = set()
|
||||||
|
|
||||||
__TEMPLATE__ = jinja2.Template(
|
__TEMPLATE__ = jinja2.Template(
|
||||||
"""# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
"""# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||||
@@ -387,6 +388,10 @@ def __make(tests_path: Text, ref_flag: bool = False) -> NoReturn:
|
|||||||
raise exceptions.TestcaseNotFound(f"Invalid tests path: {tests_path}")
|
raise exceptions.TestcaseNotFound(f"Invalid tests path: {tests_path}")
|
||||||
|
|
||||||
for test_file in test_files:
|
for test_file in test_files:
|
||||||
|
if test_file.lower().endswith("_test.py"):
|
||||||
|
pytest_files_set.add(test_file)
|
||||||
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
test_content = load_test_file(test_file)
|
test_content = load_test_file(test_file)
|
||||||
except (exceptions.FileNotFound, exceptions.FileFormatError) as ex:
|
except (exceptions.FileNotFound, exceptions.FileFormatError) as ex:
|
||||||
@@ -419,15 +424,19 @@ def __make(tests_path: Text, ref_flag: bool = False) -> NoReturn:
|
|||||||
|
|
||||||
|
|
||||||
def main_make(tests_paths: List[Text]) -> List[Text]:
|
def main_make(tests_paths: List[Text]) -> List[Text]:
|
||||||
|
if not tests_paths:
|
||||||
|
return []
|
||||||
|
|
||||||
for tests_path in tests_paths:
|
for tests_path in tests_paths:
|
||||||
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)
|
||||||
|
|
||||||
__make(tests_path)
|
__make(tests_path)
|
||||||
|
|
||||||
testcase_path_list = list(make_files_cache_set)
|
pytest_files_set.update(make_files_cache_set)
|
||||||
format_pytest_with_black(*testcase_path_list)
|
pytest_files_list = list(pytest_files_set)
|
||||||
return testcase_path_list
|
format_pytest_with_black(*pytest_files_list)
|
||||||
|
return pytest_files_list
|
||||||
|
|
||||||
|
|
||||||
def init_make_parser(subparsers):
|
def init_make_parser(subparsers):
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class TestHar(TestHar2CaseUtils):
|
|||||||
self.assertIn("validate", teststeps[0])
|
self.assertIn("validate", teststeps[0])
|
||||||
|
|
||||||
def test_gen_testcase_yaml(self):
|
def test_gen_testcase_yaml(self):
|
||||||
yaml_file = os.path.join(os.path.dirname(__file__), "data", "demo.yaml")
|
yaml_file = os.path.join(os.path.dirname(__file__), "data", "demo.yml")
|
||||||
|
|
||||||
self.har_parser.gen_testcase(file_type="YAML")
|
self.har_parser.gen_testcase(file_type="YAML")
|
||||||
self.assertTrue(os.path.isfile(yaml_file))
|
self.assertTrue(os.path.isfile(yaml_file))
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ from httprunner.make import (
|
|||||||
make_files_cache_set,
|
make_files_cache_set,
|
||||||
make_config_chain_style,
|
make_config_chain_style,
|
||||||
make_teststep_chain_style,
|
make_teststep_chain_style,
|
||||||
|
pytest_files_set,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestLoader(unittest.TestCase):
|
class TestMake(unittest.TestCase):
|
||||||
def test_make_testcase(self):
|
def test_make_testcase(self):
|
||||||
path = ["examples/postman_echo/request_methods/request_with_variables.yml"]
|
path = ["examples/postman_echo/request_methods/request_with_variables.yml"]
|
||||||
testcase_python_list = main_make(path)
|
testcase_python_list = main_make(path)
|
||||||
@@ -23,6 +24,7 @@ class TestLoader(unittest.TestCase):
|
|||||||
"examples/postman_echo/request_methods/request_with_testcase_reference.yml"
|
"examples/postman_echo/request_methods/request_with_testcase_reference.yml"
|
||||||
]
|
]
|
||||||
make_files_cache_set.clear()
|
make_files_cache_set.clear()
|
||||||
|
pytest_files_set.clear()
|
||||||
testcase_python_list = main_make(path)
|
testcase_python_list = main_make(path)
|
||||||
self.assertEqual(len(testcase_python_list), 1)
|
self.assertEqual(len(testcase_python_list), 1)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
@@ -91,6 +93,7 @@ from examples.postman_echo.request_methods.request_with_functions_test import (
|
|||||||
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"]
|
||||||
make_files_cache_set.clear()
|
make_files_cache_set.clear()
|
||||||
|
pytest_files_set.clear()
|
||||||
testcase_python_list = main_make(path)
|
testcase_python_list = main_make(path)
|
||||||
self.assertEqual(len(testcase_python_list), 2)
|
self.assertEqual(len(testcase_python_list), 2)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
|
|||||||
Reference in New Issue
Block a user