fix #551: raise if times is not digit

This commit is contained in:
debugtalk
2019-07-14 23:22:17 +08:00
parent ee4a18e535
commit 722555bafb
3 changed files with 43 additions and 2 deletions

View File

@@ -10,6 +10,7 @@
**Fixed**
- fix #574: delete unnecessary code
- fix #551: raise if times is not digit
## 2.2.3 (2019-06-30)

View File

@@ -85,7 +85,14 @@ class HttpRunner(object):
tests = testcase.get("teststeps", [])
for index, test_dict in enumerate(tests):
for times_index in range(int(test_dict.get("times", 1))):
times = test_dict.get("times", 1)
try:
times = int(times)
except ValueError:
raise exceptions.ParamsError(
"times should be digit, given: {}".format(times))
for times_index in range(times):
# suppose one testcase should not have more than 9999 steps,
# and one step should not run more than 999 times.
test_method_name = 'test_{:04}_{:03}'.format(index, times_index)

View File

@@ -4,7 +4,7 @@ import shutil
import time
import unittest
from httprunner import loader, parser
from httprunner import exceptions, loader, parser
from httprunner.api import HttpRunner, prepare_locust_tests
from tests.api_server import HTTPBIN_SERVER
from tests.base import ApiServerUnittest
@@ -80,6 +80,39 @@ class TestHttpRunner(ApiServerUnittest):
self.assertEqual(self.runner.summary["stat"]["testcases"]["total"], 1)
self.assertEqual(self.runner.summary["stat"]["teststeps"]["total"], 10)
def test_text_run_times_invalid(self):
testcases = [
{
"config": {
'name': "post data",
'variables': []
},
"teststeps": [
{
"name": "post data",
"times": "1.5",
"request": {
"url": "{}/post".format(HTTPBIN_SERVER),
"method": "POST",
"headers": {
"User-Agent": "python-requests/2.18.4",
"Content-Type": "application/json"
},
"data": "abc"
},
"validate": [
{"eq": ["status_code", 200]}
]
}
]
}
]
tests_mapping = {
"testcases": testcases
}
with self.assertRaises(exceptions.ParamsError):
self.runner.run_tests(tests_mapping)
def test_text_skip(self):
self.runner.run(self.testcase_cli_path)
self.assertEqual(self.runner.summary["stat"]["teststeps"]["skipped"], 4)