mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-25 01:59:52 +08:00
runner: rename method name
This commit is contained in:
@@ -2,17 +2,16 @@
|
|||||||
import zmq
|
import zmq
|
||||||
import os
|
import os
|
||||||
from locust import HttpLocust, TaskSet, task
|
from locust import HttpLocust, TaskSet, task
|
||||||
from ate import testcase, runner, exception
|
from ate import runner, exception
|
||||||
|
|
||||||
class WebPageTasks(TaskSet):
|
class WebPageTasks(TaskSet):
|
||||||
def on_start(self):
|
def on_start(self):
|
||||||
self.test_runner = runner.Runner(self.client)
|
self.test_runner = runner.Runner(self.client)
|
||||||
self.testset = self.locust.testset
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def test_specified_scenario(self):
|
def test_specified_scenario(self):
|
||||||
try:
|
try:
|
||||||
self.test_runner.run_testset(self.testset)
|
self.test_runner.run(self.locust.file_path)
|
||||||
except exception.ValidationError:
|
except exception.ValidationError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -22,4 +21,4 @@ class WebPageUser(HttpLocust):
|
|||||||
min_wait = 1000
|
min_wait = 1000
|
||||||
max_wait = 5000
|
max_wait = 5000
|
||||||
|
|
||||||
testset = testcase.load_test_file("$TESTCASE_FILE")
|
file_path = "$TESTCASE_FILE"
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class Runner(object):
|
|||||||
|
|
||||||
return parsed_request
|
return parsed_request
|
||||||
|
|
||||||
def run_test(self, testcase):
|
def _run_test(self, testcase):
|
||||||
""" run single testcase.
|
""" run single testcase.
|
||||||
@param (dict) testcase
|
@param (dict) testcase
|
||||||
{
|
{
|
||||||
@@ -124,7 +124,7 @@ class Runner(object):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def run_testset(self, testset, variables_mapping=None):
|
def _run_testset(self, testset, variables_mapping=None):
|
||||||
""" run single testset, including one or several testcases.
|
""" run single testset, including one or several testcases.
|
||||||
@param
|
@param
|
||||||
(dict) testset
|
(dict) testset
|
||||||
@@ -168,7 +168,7 @@ class Runner(object):
|
|||||||
testcases = testset.get("testcases", [])
|
testcases = testset.get("testcases", [])
|
||||||
for testcase in testcases:
|
for testcase in testcases:
|
||||||
try:
|
try:
|
||||||
assert self.run_test(testcase)
|
assert self._run_test(testcase)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
success = False
|
success = False
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ class Runner(object):
|
|||||||
testsets = testcase.load_testcases_by_path(path)
|
testsets = testcase.load_testcases_by_path(path)
|
||||||
for testset in testsets:
|
for testset in testsets:
|
||||||
try:
|
try:
|
||||||
result = self.run_testset(testset, mapping)
|
result = self._run_testset(testset, mapping)
|
||||||
assert result["success"]
|
assert result["success"]
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
success = False
|
success = False
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ 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))
|
self.assertTrue(self.test_runner._run_test(self.testcase))
|
||||||
|
|
||||||
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.
|
||||||
|
|||||||
@@ -28,13 +28,13 @@ class TestRunner(ApiServerUnittest):
|
|||||||
for testcase_file_path in self.testcase_file_path_list:
|
for testcase_file_path in self.testcase_file_path_list:
|
||||||
testcases = utils.load_tests(testcase_file_path)
|
testcases = utils.load_tests(testcase_file_path)
|
||||||
testcase = testcases[0]["test"]
|
testcase = testcases[0]["test"]
|
||||||
self.assertTrue(self.test_runner.run_test(testcase))
|
self.assertTrue(self.test_runner._run_test(testcase))
|
||||||
|
|
||||||
testcase = testcases[1]["test"]
|
testcase = testcases[1]["test"]
|
||||||
self.assertTrue(self.test_runner.run_test(testcase))
|
self.assertTrue(self.test_runner._run_test(testcase))
|
||||||
|
|
||||||
testcase = testcases[2]["test"]
|
testcase = testcases[2]["test"]
|
||||||
self.assertTrue(self.test_runner.run_test(testcase))
|
self.assertTrue(self.test_runner._run_test(testcase))
|
||||||
|
|
||||||
def test_run_single_testcase_fail(self):
|
def test_run_single_testcase_fail(self):
|
||||||
testcase = {
|
testcase = {
|
||||||
@@ -63,12 +63,11 @@ class TestRunner(ApiServerUnittest):
|
|||||||
}
|
}
|
||||||
|
|
||||||
with self.assertRaises(exception.ValidationError):
|
with self.assertRaises(exception.ValidationError):
|
||||||
self.test_runner.run_test(testcase)
|
self.test_runner._run_test(testcase)
|
||||||
|
|
||||||
def test_run_testset_hardcode(self):
|
def test_run_testset_hardcode(self):
|
||||||
for testcase_file_path in self.testcase_file_path_list:
|
for testcase_file_path in self.testcase_file_path_list:
|
||||||
testset = testcase.load_test_file(testcase_file_path)
|
result = self.test_runner.run(testcase_file_path)
|
||||||
result = self.test_runner.run_testset(testset)
|
|
||||||
self.assertTrue(result["success"])
|
self.assertTrue(result["success"])
|
||||||
|
|
||||||
def test_run_testsets_hardcode(self):
|
def test_run_testsets_hardcode(self):
|
||||||
@@ -79,15 +78,13 @@ class TestRunner(ApiServerUnittest):
|
|||||||
def test_run_testset_template_variables(self):
|
def test_run_testset_template_variables(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'tests/data/demo_testset_variables.yml')
|
os.getcwd(), 'tests/data/demo_testset_variables.yml')
|
||||||
testset = testcase.load_test_file(testcase_file_path)
|
result = self.test_runner.run(testcase_file_path)
|
||||||
result = self.test_runner.run_testset(testset)
|
|
||||||
self.assertTrue(result["success"])
|
self.assertTrue(result["success"])
|
||||||
|
|
||||||
def test_run_testset_template_import_functions(self):
|
def test_run_testset_template_import_functions(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'tests/data/demo_testset_template_import_functions.yml')
|
os.getcwd(), 'tests/data/demo_testset_template_import_functions.yml')
|
||||||
testset = testcase.load_test_file(testcase_file_path)
|
result = self.test_runner.run(testcase_file_path)
|
||||||
result = self.test_runner.run_testset(testset)
|
|
||||||
self.assertTrue(result["success"])
|
self.assertTrue(result["success"])
|
||||||
|
|
||||||
def test_run_testsets_template_import_functions(self):
|
def test_run_testsets_template_import_functions(self):
|
||||||
@@ -111,18 +108,16 @@ class TestRunner(ApiServerUnittest):
|
|||||||
def test_run_testset_output(self):
|
def test_run_testset_output(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'tests/data/demo_testset_layer.yml')
|
os.getcwd(), 'tests/data/demo_testset_layer.yml')
|
||||||
testset = testcase.load_test_file(testcase_file_path)
|
result = self.test_runner.run(testcase_file_path)
|
||||||
result = self.test_runner.run_testset(testset)
|
|
||||||
self.assertTrue(result["success"])
|
self.assertTrue(result["success"])
|
||||||
self.assertIn("token", result["output"])
|
self.assertIn("token", result["output"])
|
||||||
|
|
||||||
def test_run_testset_with_variables_mapping(self):
|
def test_run_testset_with_variables_mapping(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'tests/data/demo_testset_layer.yml')
|
os.getcwd(), 'tests/data/demo_testset_layer.yml')
|
||||||
testset = testcase.load_test_file(testcase_file_path)
|
|
||||||
variables_mapping = {
|
variables_mapping = {
|
||||||
"app_version": '2.9.7'
|
"app_version": '2.9.7'
|
||||||
}
|
}
|
||||||
result = self.test_runner.run_testset(testset, variables_mapping)
|
result = self.test_runner.run(testcase_file_path, variables_mapping)
|
||||||
self.assertTrue(result["success"])
|
self.assertTrue(result["success"])
|
||||||
self.assertIn("token", result["output"])
|
self.assertIn("token", result["output"])
|
||||||
|
|||||||
Reference in New Issue
Block a user