mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-03 06:49:38 +08:00
test: update examples
This commit is contained in:
@@ -102,7 +102,6 @@ def make_testcase(testcase: Dict) -> Union[str, None]:
|
||||
}
|
||||
content = template.render(data)
|
||||
|
||||
os.makedirs(os.path.dirname(testcase_python_path), exist_ok=True)
|
||||
with open(testcase_python_path, "w") as f:
|
||||
f.write(content)
|
||||
|
||||
@@ -134,6 +133,9 @@ def make_testsuite(testsuite: Dict) -> List[Text]:
|
||||
|
||||
logger.info(f"start to make testsuite: {testsuite_path}")
|
||||
|
||||
# create directory with testsuite file name, put its testcases under this directory
|
||||
os.makedirs(os.path.dirname(os.path.splitext(testsuite_path)[0]), exist_ok=True)
|
||||
|
||||
testcase_files = []
|
||||
|
||||
for testcase in testsuite["testcases"]:
|
||||
@@ -142,6 +144,9 @@ def make_testsuite(testsuite: Dict) -> List[Text]:
|
||||
testcase_path = os.path.join(project_working_directory, testcase_file)
|
||||
testcase_dict = load_test_file(testcase_path)
|
||||
testcase_dict.setdefault("config", {})
|
||||
testcase_dict["config"]["path"] = os.path.join(
|
||||
os.path.splitext(testsuite_path)[0], os.path.basename(testcase_path)
|
||||
)
|
||||
|
||||
# override testcase name
|
||||
testcase_dict["config"]["name"] = testcase["name"]
|
||||
@@ -154,11 +159,6 @@ def make_testsuite(testsuite: Dict) -> List[Text]:
|
||||
testcase_dict["config"]["variables"].update(testcase.get("variables", {}))
|
||||
testcase_dict["config"]["variables"].update(testsuite_variables)
|
||||
|
||||
# create directory with testsuite file name, put its testcases under this directory
|
||||
testcase_dict["config"]["path"] = os.path.join(
|
||||
os.path.splitext(testsuite_path)[0], os.path.basename(testcase_path)
|
||||
)
|
||||
|
||||
# make testcase
|
||||
testcase_path = make_testcase(testcase_dict)
|
||||
testcase_files.append(testcase_path)
|
||||
|
||||
@@ -9,11 +9,11 @@ class TestHttpRunner(unittest.TestCase):
|
||||
|
||||
def test_run_testcase_by_path_request_only(self):
|
||||
self.runner.run_path(
|
||||
"examples/postman_echo/request_methods/request_with_variables.yml"
|
||||
"examples/postman_echo/request_methods/request_with_functions.yml"
|
||||
)
|
||||
result = self.runner.get_summary()
|
||||
self.assertTrue(result.success)
|
||||
self.assertEqual(result.name, "request methods testcase with variables")
|
||||
self.assertEqual(result.name, "request methods testcase with functions")
|
||||
self.assertEqual(result.step_datas[0].name, "get with params")
|
||||
self.assertEqual(len(result.step_datas), 3)
|
||||
|
||||
@@ -24,5 +24,5 @@ class TestHttpRunner(unittest.TestCase):
|
||||
result = self.runner.get_summary()
|
||||
self.assertTrue(result.success)
|
||||
self.assertEqual(result.name, "request methods testcase: reference testcase")
|
||||
self.assertEqual(result.step_datas[0].name, "request with variables")
|
||||
self.assertEqual(result.step_datas[0].name, "request with functions")
|
||||
self.assertEqual(len(result.step_datas), 1)
|
||||
|
||||
Reference in New Issue
Block a user