mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-16 11:37:39 +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:
|
||||
self.fail(str(ex))
|
||||
finally:
|
||||
if hasattr(test_runner.http_client_session, "meta_data"):
|
||||
self.meta_data = test_runner.http_client_session.meta_data
|
||||
self.meta_data["validators"] = test_runner.evaluated_validators
|
||||
test_runner.http_client_session.init_meta_data()
|
||||
self.meta_data = test_runner.get_test_data()
|
||||
|
||||
if "config" in test_dict:
|
||||
# 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
|
||||
|
||||
test_suite = unittest.TestSuite()
|
||||
|
||||
@@ -186,11 +186,8 @@ class HtmlTestResult(unittest.TextTestResult):
|
||||
'name': test.shortDescription(),
|
||||
'status': status,
|
||||
'attachment': attachment,
|
||||
"meta_data": {}
|
||||
"meta_data": test.meta_data
|
||||
}
|
||||
if hasattr(test, "meta_data"):
|
||||
data["meta_data"] = test.meta_data
|
||||
|
||||
self.records.append(data)
|
||||
|
||||
def startTestRun(self):
|
||||
|
||||
@@ -68,6 +68,19 @@ class Runner(object):
|
||||
if self.testcase_teardown_hooks:
|
||||
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):
|
||||
""" handle skip feature for test
|
||||
- skip: skip current test unconditionally
|
||||
@@ -162,6 +175,9 @@ class Runner(object):
|
||||
exceptions.ExtractFailure
|
||||
|
||||
"""
|
||||
# clear meta data first to ensure independence for each test
|
||||
self.clear_test_data()
|
||||
|
||||
# check skip
|
||||
self._handle_skip_feature(test_dict)
|
||||
|
||||
@@ -270,7 +286,7 @@ class Runner(object):
|
||||
}
|
||||
}
|
||||
|
||||
# embeded testcase
|
||||
# nested testcase
|
||||
{
|
||||
"config": {...},
|
||||
"tests": [
|
||||
@@ -287,6 +303,7 @@ class Runner(object):
|
||||
|
||||
"""
|
||||
if "config" in test_dict:
|
||||
# nested testcase
|
||||
self._run_testcase(test_dict)
|
||||
else:
|
||||
# api
|
||||
|
||||
Reference in New Issue
Block a user