mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-08 07:51:25 +08:00
fix #363: clear meta data first to ensure independence for each test
This commit is contained in:
@@ -47,13 +47,15 @@ class HttpRunner(object):
|
|||||||
except exceptions.MyBaseFailure as ex:
|
except exceptions.MyBaseFailure as ex:
|
||||||
self.fail(str(ex))
|
self.fail(str(ex))
|
||||||
finally:
|
finally:
|
||||||
if hasattr(test_runner.http_client_session, "meta_data"):
|
self.meta_data = test_runner.get_test_data()
|
||||||
self.meta_data = test_runner.http_client_session.meta_data
|
|
||||||
self.meta_data["validators"] = test_runner.evaluated_validators
|
if "config" in test_dict:
|
||||||
test_runner.http_client_session.init_meta_data()
|
# run nested testcase
|
||||||
|
test.__doc__ = test_dict["config"].get("name")
|
||||||
|
else:
|
||||||
|
# run api test
|
||||||
|
test.__doc__ = test_dict.get("name")
|
||||||
|
|
||||||
# TODO: refactor
|
|
||||||
test.__doc__ = test_dict.get("name") or test_dict.get("config", {}).get("name")
|
|
||||||
return test
|
return test
|
||||||
|
|
||||||
test_suite = unittest.TestSuite()
|
test_suite = unittest.TestSuite()
|
||||||
|
|||||||
@@ -186,11 +186,8 @@ class HtmlTestResult(unittest.TextTestResult):
|
|||||||
'name': test.shortDescription(),
|
'name': test.shortDescription(),
|
||||||
'status': status,
|
'status': status,
|
||||||
'attachment': attachment,
|
'attachment': attachment,
|
||||||
"meta_data": {}
|
"meta_data": test.meta_data
|
||||||
}
|
}
|
||||||
if hasattr(test, "meta_data"):
|
|
||||||
data["meta_data"] = test.meta_data
|
|
||||||
|
|
||||||
self.records.append(data)
|
self.records.append(data)
|
||||||
|
|
||||||
def startTestRun(self):
|
def startTestRun(self):
|
||||||
|
|||||||
@@ -68,6 +68,19 @@ class Runner(object):
|
|||||||
if self.testcase_teardown_hooks:
|
if self.testcase_teardown_hooks:
|
||||||
self.do_hook_actions(self.testcase_teardown_hooks, "teardown")
|
self.do_hook_actions(self.testcase_teardown_hooks, "teardown")
|
||||||
|
|
||||||
|
def clear_test_data(self):
|
||||||
|
""" clear request and response data
|
||||||
|
"""
|
||||||
|
self.evaluated_validators = []
|
||||||
|
self.http_client_session.init_meta_data()
|
||||||
|
|
||||||
|
def get_test_data(self):
|
||||||
|
""" get request/response data and validate results
|
||||||
|
"""
|
||||||
|
meta_data = self.http_client_session.meta_data
|
||||||
|
meta_data["validators"] = self.evaluated_validators
|
||||||
|
return meta_data
|
||||||
|
|
||||||
def _handle_skip_feature(self, test_dict):
|
def _handle_skip_feature(self, test_dict):
|
||||||
""" handle skip feature for test
|
""" handle skip feature for test
|
||||||
- skip: skip current test unconditionally
|
- skip: skip current test unconditionally
|
||||||
@@ -162,6 +175,9 @@ class Runner(object):
|
|||||||
exceptions.ExtractFailure
|
exceptions.ExtractFailure
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
# clear meta data first to ensure independence for each test
|
||||||
|
self.clear_test_data()
|
||||||
|
|
||||||
# check skip
|
# check skip
|
||||||
self._handle_skip_feature(test_dict)
|
self._handle_skip_feature(test_dict)
|
||||||
|
|
||||||
@@ -270,7 +286,7 @@ class Runner(object):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# embeded testcase
|
# nested testcase
|
||||||
{
|
{
|
||||||
"config": {...},
|
"config": {...},
|
||||||
"tests": [
|
"tests": [
|
||||||
@@ -287,6 +303,7 @@ class Runner(object):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
if "config" in test_dict:
|
if "config" in test_dict:
|
||||||
|
# nested testcase
|
||||||
self._run_testcase(test_dict)
|
self._run_testcase(test_dict)
|
||||||
else:
|
else:
|
||||||
# api
|
# api
|
||||||
|
|||||||
Reference in New Issue
Block a user