mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-27 11:10:31 +08:00
bugfix #96 skip feature: display skip testcases number corretly
This commit is contained in:
@@ -15,7 +15,11 @@ class ApiTestCase(unittest.TestCase):
|
|||||||
def runTest(self):
|
def runTest(self):
|
||||||
""" run testcase and check result.
|
""" run testcase and check result.
|
||||||
"""
|
"""
|
||||||
self.assertTrue(self.test_runner._run_test(self.testcase_dict))
|
skip_current_test = self.testcase_dict.get("skip", False)
|
||||||
|
if skip_current_test:
|
||||||
|
self.skipTest("skip this test")
|
||||||
|
else:
|
||||||
|
self.assertTrue(self.test_runner._run_test(self.testcase_dict))
|
||||||
|
|
||||||
class ApiTestSuite(unittest.TestSuite):
|
class ApiTestSuite(unittest.TestSuite):
|
||||||
""" create test suite with a testset, it may include one or several testcases.
|
""" create test suite with a testset, it may include one or several testcases.
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
- test:
|
- test:
|
||||||
name: create user which existed
|
name: create user which existed
|
||||||
times: 3
|
times: 2
|
||||||
request:
|
request:
|
||||||
url: http://127.0.0.1:5000/api/users/1000
|
url: http://127.0.0.1:5000/api/users/1000
|
||||||
method: POST
|
method: POST
|
||||||
@@ -65,4 +65,25 @@
|
|||||||
- sum_status_code: ["status_code", 5]
|
- sum_status_code: ["status_code", 5]
|
||||||
- "eq": ["content.success", false]
|
- "eq": ["content.success", false]
|
||||||
- {"check": "status_code", "comparator": "eq", "expect": 500}
|
- {"check": "status_code", "comparator": "eq", "expect": 500}
|
||||||
- {"check": "content.success", "comparator": "eq", "expect": false}
|
- {"check": "content.success", "comparator": "eq", "expect": false}
|
||||||
|
|
||||||
|
- test:
|
||||||
|
name: create user which existed (skipped)
|
||||||
|
skip: True
|
||||||
|
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}
|
||||||
|
|||||||
@@ -9,16 +9,27 @@ from tests.base import ApiServerUnittest
|
|||||||
|
|
||||||
class TestCli(ApiServerUnittest):
|
class TestCli(ApiServerUnittest):
|
||||||
|
|
||||||
def test_run_times(self):
|
def setUp(self):
|
||||||
testset_path = "tests/data/demo_testset_cli.yml"
|
testset_path = "tests/data/demo_testset_cli.yml"
|
||||||
output_folder_name = os.path.basename(os.path.splitext(testset_path)[0])
|
output_folder_name = os.path.basename(os.path.splitext(testset_path)[0])
|
||||||
kwargs = {
|
self.kwargs = {
|
||||||
"output": output_folder_name
|
"output": output_folder_name
|
||||||
}
|
}
|
||||||
|
self.task_suite = TaskSuite(testset_path)
|
||||||
|
self.report_save_dir = os.path.join(os.getcwd(), 'reports', output_folder_name)
|
||||||
|
self.reset_all()
|
||||||
|
|
||||||
task_suite = TaskSuite(testset_path)
|
def reset_all(self):
|
||||||
result = HTMLTestRunner(**kwargs).run(task_suite)
|
url = "%s/api/reset-all" % self.host
|
||||||
self.assertEqual(result.testsRun, 5)
|
headers = self.get_authenticated_headers()
|
||||||
|
return self.api_client.get(url, headers=headers)
|
||||||
|
|
||||||
report_save_dir = os.path.join(os.getcwd(), 'reports', output_folder_name)
|
def test_run_times(self):
|
||||||
shutil.rmtree(report_save_dir)
|
result = HTMLTestRunner(**self.kwargs).run(self.task_suite)
|
||||||
|
self.assertEqual(result.testsRun, 6)
|
||||||
|
shutil.rmtree(self.report_save_dir)
|
||||||
|
|
||||||
|
def test_skip(self):
|
||||||
|
result = HTMLTestRunner(**self.kwargs).run(self.task_suite)
|
||||||
|
self.assertEqual(len(result.skipped), 2)
|
||||||
|
shutil.rmtree(self.report_save_dir)
|
||||||
|
|||||||
Reference in New Issue
Block a user