bugfix #53: ensure teardown functions executed when test fail

This commit is contained in:
debugtalk
2017-11-13 22:53:09 +08:00
parent bb9eb11161
commit f9e9f75f05
3 changed files with 10 additions and 4 deletions

View File

@@ -1 +1 @@
__version__ = '0.8.1c'
__version__ = '0.8.1d'

View File

@@ -138,8 +138,8 @@ class Runner(object):
err_msg += u"HTTP response content: \n{}".format(resp.text)
logging.error(err_msg)
raise
setup_teardown(teardown_actions)
finally:
setup_teardown(teardown_actions)
return True

View File

@@ -1,4 +1,5 @@
import os
import time
from httprunner import exception, runner, testcase
@@ -58,11 +59,16 @@ class TestRunner(ApiServerUnittest):
"validate": [
{"check": "status_code", "expect": 205},
{"check": "content.token", "comparator": "len_eq", "expect": 19}
]
],
"teardown": ["${sleep(2)}"]
}
with self.assertRaises(exception.ValidationError):
start_time = time.time()
self.test_runner._run_test(test)
end_time = time.time()
# check if teardown function executed
self.assertGreater(end_time - start_time, 2)
def test_run_testset_hardcode(self):
for testcase_file_path in self.testcase_file_path_list: