mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 09:49:33 +08:00
refactor parameterization:
parameter value now can be in three types: (1) data list (2) call built-in parameterize function (3) call custom function in debugtalk.py
This commit is contained in:
@@ -48,3 +48,15 @@ def skip_test_in_production_env():
|
||||
""" skip this test in production environment
|
||||
"""
|
||||
return os.environ["TEST_ENV"] == "PRODUCTION"
|
||||
|
||||
def gen_app_version():
|
||||
return [
|
||||
{"app_version": "2.8.5"},
|
||||
{"app_version": "2.8.6"}
|
||||
]
|
||||
|
||||
def get_account():
|
||||
return [
|
||||
{"username": "user1", "password": "111111"},
|
||||
{"username": "user2", "password": "222222"}
|
||||
]
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
- config:
|
||||
name: "user management testset."
|
||||
parameters:
|
||||
- user_agent: Random
|
||||
- app_version: Sequential
|
||||
- user_agent: ["iOS/10.1", "iOS/10.2", "iOS/10.3"]
|
||||
- app_version: ${gen_app_version()}
|
||||
- username: ${parameterize(account.csv)}
|
||||
variables:
|
||||
- user_agent: 'iOS/10.3'
|
||||
- device_sn: ${gen_random_string(15)}
|
||||
- os_platform: 'ios'
|
||||
- app_version: '2.8.6'
|
||||
request:
|
||||
base_url: $BASE_URL
|
||||
headers:
|
||||
@@ -17,7 +17,7 @@
|
||||
- token
|
||||
|
||||
- test:
|
||||
name: get token with $user_agent and $app_version
|
||||
name: get token with $user_agent and $app_version, username $username
|
||||
api: get_token($user_agent, $device_sn, $os_platform, $app_version)
|
||||
extract:
|
||||
- token: content.token
|
||||
|
||||
@@ -164,4 +164,4 @@ class TestRunner(ApiServerUnittest):
|
||||
result = HttpRunner(testcase_file_path).run()
|
||||
self.assertTrue(result["success"])
|
||||
self.assertIn("token", result["output"])
|
||||
self.assertEqual(result["stat"]["testsRun"], 6)
|
||||
self.assertEqual(result["stat"]["testsRun"], 3 * 2 * 3)
|
||||
|
||||
@@ -51,7 +51,7 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
|
||||
def test_load_csv_file_multiple_parameters(self):
|
||||
csv_file_path = os.path.join(
|
||||
os.getcwd(), 'tests/data/username-password.csv')
|
||||
os.getcwd(), 'tests/data/account.csv')
|
||||
csv_content = testcase.load_file(csv_file_path)
|
||||
self.assertEqual(
|
||||
csv_content,
|
||||
@@ -105,40 +105,70 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
product_list = testcase.gen_cartesian_product(*parameters_content_list)
|
||||
self.assertEqual(product_list, [])
|
||||
|
||||
def test_gen_cartesian_product_parameters_one_to_one(self):
|
||||
def test_parse_parameters_raw_list(self):
|
||||
parameters = [
|
||||
{"user_agent": "random"},
|
||||
{"app_version": "sequential"}
|
||||
{"user_agent": ["iOS/10.1", "iOS/10.2", "iOS/10.3"]},
|
||||
{"username-password": [("user1", "111111"), ("test2", "222222")]}
|
||||
]
|
||||
testset_path = os.path.join(
|
||||
os.getcwd(),
|
||||
"tests/data/demo_parameters.yml"
|
||||
)
|
||||
cartesian_product_parameters = testcase.gen_cartesian_product_parameters(
|
||||
parameters,
|
||||
testset_path
|
||||
)
|
||||
cartesian_product_parameters = testcase.parse_parameters(parameters)
|
||||
self.assertEqual(
|
||||
len(cartesian_product_parameters),
|
||||
6
|
||||
3 * 2
|
||||
)
|
||||
|
||||
def test_gen_cartesian_product_parameters_one_to_multiple(self):
|
||||
def test_parse_parameters_parameterize(self):
|
||||
parameters = [
|
||||
{"user_agent": "random"},
|
||||
{"username-password": "sequential"}
|
||||
{"app_version": "${parameterize(app_version.csv)}"},
|
||||
{"username-password": "${parameterize(account.csv)}"}
|
||||
]
|
||||
testset_path = os.path.join(
|
||||
os.getcwd(),
|
||||
"tests/data/demo_parameters.yml"
|
||||
)
|
||||
cartesian_product_parameters = testcase.gen_cartesian_product_parameters(
|
||||
cartesian_product_parameters = testcase.parse_parameters(
|
||||
parameters,
|
||||
testset_path
|
||||
)
|
||||
self.assertEqual(
|
||||
len(cartesian_product_parameters),
|
||||
9
|
||||
2 * 3
|
||||
)
|
||||
|
||||
def test_parse_parameters_custom_function(self):
|
||||
parameters = [
|
||||
{"app_version": "${gen_app_version()}"},
|
||||
{"username-password": "${get_account()}"}
|
||||
]
|
||||
testset_path = os.path.join(
|
||||
os.getcwd(),
|
||||
"tests/data/demo_parameters.yml"
|
||||
)
|
||||
cartesian_product_parameters = testcase.parse_parameters(
|
||||
parameters,
|
||||
testset_path
|
||||
)
|
||||
self.assertEqual(
|
||||
len(cartesian_product_parameters),
|
||||
2 * 2
|
||||
)
|
||||
|
||||
def test_parse_parameters_mix(self):
|
||||
parameters = [
|
||||
{"user_agent": ["iOS/10.1", "iOS/10.2", "iOS/10.3"]},
|
||||
{"app_version": "${gen_app_version()}"},
|
||||
{"username-password": "${parameterize(account.csv)}"}
|
||||
]
|
||||
testset_path = os.path.join(
|
||||
os.getcwd(),
|
||||
"tests/data/demo_parameters.yml"
|
||||
)
|
||||
cartesian_product_parameters = testcase.parse_parameters(
|
||||
parameters,
|
||||
testset_path
|
||||
)
|
||||
self.assertEqual(
|
||||
len(cartesian_product_parameters),
|
||||
3 * 2 * 3
|
||||
)
|
||||
|
||||
def test_load_yaml_file_file_format_error(self):
|
||||
|
||||
Reference in New Issue
Block a user