mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: run testcase with debugtalk_py python script
This commit is contained in:
@@ -14,10 +14,24 @@ async def debug_single_testcase(project_meta: ProjectMeta, testcase: TestCase):
|
||||
"message": "success",
|
||||
"result": {}
|
||||
}
|
||||
|
||||
project_meta_json = project_meta.dict(by_alias=True)
|
||||
if project_meta.debugtalk_py:
|
||||
origin_local_keys = list(locals().keys()).copy()
|
||||
exec(project_meta.debugtalk_py, {}, locals())
|
||||
new_local_keys = list(locals().keys()).copy()
|
||||
new_added_keys = set(new_local_keys) - set(origin_local_keys)
|
||||
new_added_keys.remove("origin_local_keys")
|
||||
project_meta_json["functions"] = {}
|
||||
for func_name in new_added_keys:
|
||||
project_meta_json["functions"][func_name] = locals()[func_name]
|
||||
|
||||
testcase_json = testcase.dict(by_alias=True)
|
||||
tests_mapping = {
|
||||
"project_mapping": project_meta,
|
||||
"testcases": [testcase]
|
||||
"project_mapping": project_meta_json,
|
||||
"testcases": [testcase_json]
|
||||
}
|
||||
|
||||
summary = runner.run_tests(tests_mapping)
|
||||
if not summary["success"]:
|
||||
resp["code"] = 1
|
||||
|
||||
51
httprunner/app/routers/debug_test.py
Normal file
51
httprunner/app/routers/debug_test.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import unittest
|
||||
|
||||
from starlette.testclient import TestClient
|
||||
|
||||
from httprunner.app.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
class TestDebug(unittest.TestCase):
|
||||
|
||||
def test_debug_single_testcase(self):
|
||||
json_data = {
|
||||
"project_meta": {
|
||||
"debugtalk_py": "\ndef hello(name):\n print(f'hello, {name}')\n",
|
||||
"variables": {},
|
||||
"env": {}
|
||||
},
|
||||
"testcase": {
|
||||
"config": {
|
||||
"name": "test demo for debug service",
|
||||
"verify": False,
|
||||
"base_url": "",
|
||||
"variables": {},
|
||||
"setup_hooks": [],
|
||||
"teardown_hooks": [],
|
||||
"export": []
|
||||
},
|
||||
"teststeps": [
|
||||
{
|
||||
"name": "get index page",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "https://httpbin.org/",
|
||||
"params": {},
|
||||
"headers": {},
|
||||
"json": {},
|
||||
"cookies": {},
|
||||
"timeout": 30,
|
||||
"allow_redirects": True,
|
||||
"verify": False
|
||||
},
|
||||
"extract": {},
|
||||
"validate": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
response = client.post("/hrun/debug/testcase", json=json_data)
|
||||
assert response.status_code == 200
|
||||
assert response.json()["code"] == 1
|
||||
@@ -12,7 +12,7 @@ Verify = bool
|
||||
Hook = List[str]
|
||||
Export = List[str]
|
||||
Extract = Dict[str, str]
|
||||
Validate = List[Dict[str, Tuple[str, Any]]]
|
||||
Validate = List[Dict]
|
||||
Env = Dict[str, Any]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user