add TeardownHooksFailure exception

This commit is contained in:
httprunner
2018-07-27 11:41:59 +08:00
parent d593d1c801
commit bc56a7501b
5 changed files with 42 additions and 5 deletions

View File

@@ -103,3 +103,7 @@ def alter_response(response):
response.headers["Content-Type"] = "html/text"
response.json["headers"]["Host"] = "127.0.0.1:8888"
response.attributes["new_attribute"] = "new_attribute"
def alter_response_error(response):
# NameError
not_defined_variable

View File

@@ -222,11 +222,37 @@ class TestRunner(ApiServerUnittest):
]
}
]
# with self.assertRaises(exceptions.AssertionError):
runner = HttpRunner().run(testsets)
summary = runner.summary
self.assertFalse(summary["success"])
self.assertEqual(summary["stat"]["failures"], 1)
def test_run_httprunner_with_teardown_hooks_error(self):
testsets = [
{
"name": "test teardown hooks",
"config": {
'path': 'tests/httpbin/hooks.yml',
},
"testcases": [
{
"name": "test teardown hooks",
"request": {
"url": "http://127.0.0.1:3458/headers",
"method": "GET",
"data": "abc"
},
"teardown_hooks": [
"${alter_response_error($response)}"
]
}
]
}
]
runner = HttpRunner().run(testsets)
summary = runner.summary
self.assertFalse(summary["success"])
self.assertEqual(summary["stat"]["errors"], 1)
def test_run_testset_with_teardown_hooks_success(self):
test = {