mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 18:11:21 +08:00
#96: skip unless condition
This commit is contained in:
@@ -67,6 +67,30 @@ class Runner(object):
|
||||
|
||||
return parsed_request
|
||||
|
||||
def _handle_skip_feature(self, testcase_dict):
|
||||
""" handle skip feature for testcase
|
||||
- skip: skip current test unconditionally
|
||||
- skipIf: skip current test if condition is true
|
||||
- skipUnless: skip current test unless condition is true
|
||||
"""
|
||||
skip_reason = None
|
||||
|
||||
if "skip" in testcase_dict:
|
||||
skip_reason = testcase_dict["skip"]
|
||||
|
||||
elif "skipIf" in testcase_dict:
|
||||
skip_if_condition = testcase_dict["skipIf"]
|
||||
if self.context.exec_content_functions(skip_if_condition):
|
||||
skip_reason = "{} evaluate to True".format(skip_if_condition)
|
||||
|
||||
elif "skipUnless" in testcase_dict:
|
||||
skip_unless_condition = testcase_dict["skipUnless"]
|
||||
if not self.context.exec_content_functions(skip_unless_condition):
|
||||
skip_reason = "{} evaluate to False".format(skip_unless_condition)
|
||||
|
||||
if skip_reason:
|
||||
raise SkipTest(skip_reason)
|
||||
|
||||
def _run_test(self, testcase_dict):
|
||||
""" run single testcase.
|
||||
@param (dict) testcase_dict
|
||||
@@ -108,14 +132,7 @@ class Runner(object):
|
||||
setup_actions = testcase_dict.get("setup", [])
|
||||
teardown_actions = testcase_dict.get("teardown", [])
|
||||
|
||||
if "skip" in testcase_dict:
|
||||
skip_reason = testcase_dict["skip"]
|
||||
raise SkipTest(skip_reason)
|
||||
elif "skipIf" in testcase_dict:
|
||||
skip_if_condition = testcase_dict["skipIf"]
|
||||
if self.context.exec_content_functions(skip_if_condition):
|
||||
skip_reason = "{} evaluate to True".format(skip_if_condition)
|
||||
raise SkipTest(skip_reason)
|
||||
self._handle_skip_feature(testcase_dict)
|
||||
|
||||
def setup_teardown(actions):
|
||||
for action in actions:
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
- {"check": "content.success", "comparator": "eq", "expect": false}
|
||||
|
||||
- test:
|
||||
name: create user which existed (skip with condition)
|
||||
name: create user which existed (skip if condition)
|
||||
skipIf: ${skip_test_in_production_env()}
|
||||
times: 2
|
||||
request:
|
||||
@@ -108,3 +108,24 @@
|
||||
- "eq": ["content.success", false]
|
||||
- {"check": "status_code", "comparator": "eq", "expect": 500}
|
||||
- {"check": "content.success", "comparator": "eq", "expect": false}
|
||||
|
||||
- test:
|
||||
name: create user which existed (skip unless condition)
|
||||
skipUnless: ${skip_test_in_production_env()}
|
||||
times: 2
|
||||
request:
|
||||
url: http://127.0.0.1:5000/api/users/1000
|
||||
method: POST
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
device_sn: 'HZfFBh6tU59EdXJ'
|
||||
token: $token
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validate:
|
||||
- "eq": ["status_code", 500]
|
||||
- sum_status_code: ["status_code", 5]
|
||||
- "eq": ["content.success", false]
|
||||
- {"check": "status_code", "comparator": "eq", "expect": 500}
|
||||
- {"check": "content.success", "comparator": "eq", "expect": false}
|
||||
|
||||
@@ -26,7 +26,7 @@ class TestCli(ApiServerUnittest):
|
||||
|
||||
def test_run_times(self):
|
||||
result = HTMLTestRunner(**self.kwargs).run(self.task_suite)
|
||||
self.assertEqual(result.testsRun, 8)
|
||||
self.assertEqual(result.testsRun, 10)
|
||||
shutil.rmtree(self.report_save_dir)
|
||||
|
||||
def test_skip(self):
|
||||
|
||||
Reference in New Issue
Block a user