diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 56b7d55f..63debb83 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,6 +5,7 @@ **Added** - feat: make pytest files in chain style +- feat: `hrun` supports run pytest files **Fixed** diff --git a/httprunner/loader.py b/httprunner/loader.py index e34d4993..aee39014 100644 --- a/httprunner/loader.py +++ b/httprunner/loader.py @@ -194,7 +194,7 @@ def load_csv_file(csv_file: Text) -> List[Dict]: 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: 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 = [] for filename in filenames: - if not filename.endswith((".yml", ".yaml", ".json")): + if not filename.lower().endswith((".yml", ".yaml", ".json", "_test.py")): continue filenames_list.append(filename) diff --git a/httprunner/make.py b/httprunner/make.py index a43be11f..c656bad9 100644 --- a/httprunner/make.py +++ b/httprunner/make.py @@ -21,6 +21,7 @@ from httprunner.response import uniform_validator """ cache converted pytest files, avoid duplicate making """ make_files_cache_set: Set = set() +pytest_files_set: Set = set() __TEMPLATE__ = jinja2.Template( """# 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}") for test_file in test_files: + if test_file.lower().endswith("_test.py"): + pytest_files_set.add(test_file) + continue + try: test_content = load_test_file(test_file) 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]: + if not tests_paths: + return [] + for tests_path in tests_paths: if not os.path.isabs(tests_path): tests_path = os.path.join(os.getcwd(), tests_path) __make(tests_path) - testcase_path_list = list(make_files_cache_set) - format_pytest_with_black(*testcase_path_list) - return testcase_path_list + pytest_files_set.update(make_files_cache_set) + pytest_files_list = list(pytest_files_set) + format_pytest_with_black(*pytest_files_list) + return pytest_files_list def init_make_parser(subparsers): diff --git a/tests/ext/har2case/core_test.py b/tests/ext/har2case/core_test.py index 329dde57..21e818ad 100644 --- a/tests/ext/har2case/core_test.py +++ b/tests/ext/har2case/core_test.py @@ -34,7 +34,7 @@ class TestHar(TestHar2CaseUtils): self.assertIn("validate", teststeps[0]) 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.assertTrue(os.path.isfile(yaml_file)) diff --git a/tests/make_test.py b/tests/make_test.py index 2189c1f7..8eec7ca6 100644 --- a/tests/make_test.py +++ b/tests/make_test.py @@ -6,10 +6,11 @@ from httprunner.make import ( make_files_cache_set, make_config_chain_style, make_teststep_chain_style, + pytest_files_set, ) -class TestLoader(unittest.TestCase): +class TestMake(unittest.TestCase): def test_make_testcase(self): path = ["examples/postman_echo/request_methods/request_with_variables.yml"] testcase_python_list = main_make(path) @@ -23,6 +24,7 @@ class TestLoader(unittest.TestCase): "examples/postman_echo/request_methods/request_with_testcase_reference.yml" ] make_files_cache_set.clear() + pytest_files_set.clear() testcase_python_list = main_make(path) self.assertEqual(len(testcase_python_list), 1) self.assertIn( @@ -91,6 +93,7 @@ from examples.postman_echo.request_methods.request_with_functions_test import ( def test_make_testsuite(self): path = ["examples/postman_echo/request_methods/demo_testsuite.yml"] make_files_cache_set.clear() + pytest_files_set.clear() testcase_python_list = main_make(path) self.assertEqual(len(testcase_python_list), 2) self.assertIn(