mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-01 19:47:11 +08:00
#96: refactor skip feature:
1, with skip keyword, skip current test unconditionally; 2, with skipIf keyword, you can skip current test with condition; condition evaluation can be defined in debugtalk.py function.
This commit is contained in:
@@ -167,7 +167,7 @@ class Context(object):
|
||||
def exec_content_functions(self, content):
|
||||
""" execute functions in content.
|
||||
"""
|
||||
self.testcase_parser.eval_content_functions(content)
|
||||
return self.testcase_parser.eval_content_functions(content)
|
||||
|
||||
def eval_check_item(self, validator, resp_obj):
|
||||
""" evaluate check item in validator
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
from unittest.case import SkipTest
|
||||
|
||||
from httprunner import exception, response, testcase, utils
|
||||
from httprunner.client import HttpSession
|
||||
@@ -107,6 +108,12 @@ class Runner(object):
|
||||
setup_actions = testcase_dict.get("setup", [])
|
||||
teardown_actions = testcase_dict.get("teardown", [])
|
||||
|
||||
if "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)
|
||||
|
||||
def setup_teardown(actions):
|
||||
for action in actions:
|
||||
self.context.exec_content_functions(action)
|
||||
|
||||
@@ -15,9 +15,9 @@ class ApiTestCase(unittest.TestCase):
|
||||
def runTest(self):
|
||||
""" run testcase and check result.
|
||||
"""
|
||||
skip_current_test = self.testcase_dict.get("skip", False)
|
||||
if skip_current_test:
|
||||
self.skipTest("skip this test")
|
||||
if "skip" in self.testcase_dict:
|
||||
skip_reason = self.testcase_dict["skip"]
|
||||
self.skipTest(skip_reason)
|
||||
else:
|
||||
self.assertTrue(self.test_runner._run_test(self.testcase_dict))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user