Skip to content

Commit

Permalink
bugfix #96 skip feature: display skip testcases number corretly
Browse files Browse the repository at this point in the history
  • Loading branch information
debugtalk committed Feb 8, 2018
1 parent 4fbc414 commit 177856c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
6 changes: 5 additions & 1 deletion httprunner/task.py
Expand Up @@ -15,7 +15,11 @@ def __init__(self, test_runner, testcase_dict):
def runTest(self):
""" 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):
""" create test suite with a testset, it may include one or several testcases.
Expand Down
25 changes: 23 additions & 2 deletions tests/data/demo_testset_cli.yml
Expand Up @@ -49,7 +49,7 @@

- test:
name: create user which existed
times: 3
times: 2
request:
url: http://127.0.0.1:5000/api/users/1000
method: POST
Expand All @@ -65,4 +65,25 @@
- sum_status_code: ["status_code", 5]
- "eq": ["content.success", false]
- {"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}
25 changes: 18 additions & 7 deletions tests/test_cli.py
Expand Up @@ -9,16 +9,27 @@

class TestCli(ApiServerUnittest):

def test_run_times(self):
def setUp(self):
testset_path = "tests/data/demo_testset_cli.yml"
output_folder_name = os.path.basename(os.path.splitext(testset_path)[0])
kwargs = {
self.kwargs = {
"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()

def reset_all(self):
url = "%s/api/reset-all" % self.host
headers = self.get_authenticated_headers()
return self.api_client.get(url, headers=headers)

task_suite = TaskSuite(testset_path)
result = HTMLTestRunner(**kwargs).run(task_suite)
self.assertEqual(result.testsRun, 5)
def test_run_times(self):
result = HTMLTestRunner(**self.kwargs).run(self.task_suite)
self.assertEqual(result.testsRun, 6)
shutil.rmtree(self.report_save_dir)

report_save_dir = os.path.join(os.getcwd(), 'reports', output_folder_name)
shutil.rmtree(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)

0 comments on commit 177856c

Please sign in to comment.