mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 23:12:41 +08:00
fix #551: raise if times is not digit
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
**Fixed**
|
**Fixed**
|
||||||
|
|
||||||
- fix #574: delete unnecessary code
|
- fix #574: delete unnecessary code
|
||||||
|
- fix #551: raise if times is not digit
|
||||||
|
|
||||||
## 2.2.3 (2019-06-30)
|
## 2.2.3 (2019-06-30)
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,14 @@ class HttpRunner(object):
|
|||||||
|
|
||||||
tests = testcase.get("teststeps", [])
|
tests = testcase.get("teststeps", [])
|
||||||
for index, test_dict in enumerate(tests):
|
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,
|
# suppose one testcase should not have more than 9999 steps,
|
||||||
# and one step should not run more than 999 times.
|
# and one step should not run more than 999 times.
|
||||||
test_method_name = 'test_{:04}_{:03}'.format(index, times_index)
|
test_method_name = 'test_{:04}_{:03}'.format(index, times_index)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import shutil
|
|||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from httprunner import loader, parser
|
from httprunner import exceptions, loader, parser
|
||||||
from httprunner.api import HttpRunner, prepare_locust_tests
|
from httprunner.api import HttpRunner, prepare_locust_tests
|
||||||
from tests.api_server import HTTPBIN_SERVER
|
from tests.api_server import HTTPBIN_SERVER
|
||||||
from tests.base import ApiServerUnittest
|
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"]["testcases"]["total"], 1)
|
||||||
self.assertEqual(self.runner.summary["stat"]["teststeps"]["total"], 10)
|
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):
|
def test_text_skip(self):
|
||||||
self.runner.run(self.testcase_cli_path)
|
self.runner.run(self.testcase_cli_path)
|
||||||
self.assertEqual(self.runner.summary["stat"]["teststeps"]["skipped"], 4)
|
self.assertEqual(self.runner.summary["stat"]["teststeps"]["skipped"], 4)
|
||||||
|
|||||||
Reference in New Issue
Block a user