Skip to content

Commit

Permalink
Merge pull request #632 from HttpRunner/rename_output
Browse files Browse the repository at this point in the history
2.2.2: rename keyword output
  • Loading branch information
debugtalk committed Jun 27, 2019
2 parents d7ca380 + 2557834 commit 3b4587d
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 39 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release History

## 2.2.2 (2019-06-26)

**Features**

- `extract` is used to replace `output` when passing former teststep's (as a testcase) export value to next teststep
- `export` is used to replace `output` in testcase config

## 2.2.1 (2019-06-25)

**Features**
Expand Down
2 changes: 1 addition & 1 deletion httprunner/__about__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__title__ = 'HttpRunner'
__description__ = 'One-stop solution for HTTP(S) testing.'
__url__ = 'https://github.com/HttpRunner/HttpRunner'
__version__ = '2.2.1'
__version__ = '2.2.2'
__author__ = 'debugtalk'
__author_email__ = 'mail@debugtalk.com'
__license__ = 'Apache-2.0'
Expand Down
8 changes: 7 additions & 1 deletion httprunner/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,13 @@ def __prepare_testcase_tests(tests, config, project_mapping, session_variables_s
if "testcase_def" in test_dict:
# test_dict is nested testcase

if "output" in test_dict:
# pass former teststep's (as a testcase) export value to next teststep
# Since V2.2.2, `extract` is used to replace `output`,
# `output` is also kept for compatibility
if "extract" in test_dict:
session_variables_set |= set(test_dict["extract"])
elif "output" in test_dict:
# kept for compatibility
session_variables_set |= set(test_dict["output"])

# 2, testcase test_dict => testcase_def config
Expand Down
10 changes: 5 additions & 5 deletions httprunner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, config, http_client_session=None):
"""
self.verify = config.get("verify", True)
self.output = config.get("output", [])
self.export = config.get("export") or config.get("output", [])
self.validation_results = []
config_variables = config.get("variables", {})

Expand Down Expand Up @@ -327,7 +327,7 @@ def _run_testcase(self, testcase_dict):
self.meta_datas.append(_meta_datas)

self.session_context.update_session_variables(
test_runner.extract_output(test_runner.output)
test_runner.export_variables(test_runner.export)
)

def run_test(self, test_dict):
Expand Down Expand Up @@ -382,16 +382,16 @@ def run_test(self, test_dict):
finally:
self.meta_datas = self.__get_test_data()

def extract_output(self, output_variables_list):
""" extract output variables
def export_variables(self, output_variables_list):
""" export current testcase variables
"""
variables_mapping = self.session_context.session_variables_mapping

output = {}
for variable in output_variables_list:
if variable not in variables_mapping:
logger.log_warning(
"variable '{}' can not be found in variables mapping, failed to output!"\
"variable '{}' can not be found in variables mapping, failed to export!"\
.format(variable)
)
continue
Expand Down
9 changes: 5 additions & 4 deletions httprunner/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def extend_variables(raw_variables, override_variables):


def get_testcase_io(testcase):
""" get and print testcase input(variables) and output.
""" get and print testcase input(variables) and output(export).
Args:
testcase (unittest.suite.TestSuite): corresponding to one YAML/JSON file, it has been set two attributes:
Expand All @@ -340,12 +340,13 @@ def get_testcase_io(testcase):
"""
test_runner = testcase.runner
variables = testcase.config.get("variables", {})
output_list = testcase.config.get("output", [])
output_mapping = test_runner.extract_output(output_list)
output_list = testcase.config.get("export") \
or testcase.config.get("output", [])
export_mapping = test_runner.export_variables(output_list)

return {
"in": variables,
"out": output_mapping
"out": export_mapping
}


Expand Down
2 changes: 1 addition & 1 deletion tests/data/demo_testcase_layer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
os_platform: 'ios'
app_version: '2.8.6'
base_url: ${get_base_url()}
output:
export:
- token

- test:
Expand Down
41 changes: 23 additions & 18 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_save_variables_output(self):
"var1": "abc",
"var2": "def"
},
"output": ["status_code", "req_data"]
"export": ["status_code", "req_data"]
},
"teststeps": [
{
Expand Down Expand Up @@ -636,23 +636,28 @@ def test_testcase_simple_run_suite(self):
self.assertEqual(len(tests_results[0][1].records), 2)

def test_testcase_complex_run_suite(self):
testcase_path = "tests/testcases/create_user.yml"
tests_mapping = loader.load_tests(testcase_path)
testcases = parser.parse_tests(tests_mapping)
runner = HttpRunner()
test_suite = runner._add_tests(testcases)
tests_results = runner._run_suite(test_suite)
self.assertEqual(len(tests_results[0][1].records), 2)

results = tests_results[0][1]
self.assertEqual(
results.records[0]["name"],
"setup and reset all (override) for TESTCASE_CREATE_XXX."
)
self.assertEqual(
results.records[1]["name"],
"create user and check result."
)
for testcase_path in [
"tests/testcases/create_user.yml",
"tests/testcases/create_user.v2.yml",
"tests/testcases/create_user.json",
"tests/testcases/create_user.v2.json"
]:
tests_mapping = loader.load_tests(testcase_path)
testcases = parser.parse_tests(tests_mapping)
runner = HttpRunner()
test_suite = runner._add_tests(testcases)
tests_results = runner._run_suite(test_suite)
self.assertEqual(len(tests_results[0][1].records), 2)

results = tests_results[0][1]
self.assertEqual(
results.records[0]["name"],
"setup and reset all (override) for TESTCASE_CREATE_XXX."
)
self.assertEqual(
results.records[1]["name"],
"create user and check result."
)

def test_testsuite_loader(self):
testcase_path = "tests/testsuites/create_users.yml"
Expand Down
3 changes: 1 addition & 2 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ def test_load_teststep_testcase(self):
"testcase": "testcases/setup.yml",
"variables": [
{"device_sn": "$device_sn"}
],
"output": ["token", "device_sn"]
]
}
testcase = loader.load_teststep(raw_test)
self.assertEqual(
Expand Down
34 changes: 34 additions & 0 deletions tests/testcases/create_user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"config": {
"id": "create_user",
"variables": {
"device_sn": "TESTCASE_CREATE_XXX",
"uid": 9001
},
"output": [
"session_token"
],
"base_url": "http://127.0.0.1:5000",
"name": "create user and check result."
}
},
{
"test": {
"testcase": "testcases/setup.yml",
"extract": [
"session_token"
],
"name": "setup and reset all (override) for $device_sn."
}
},
{
"test": {
"testcase": "testcases/deps/check_and_create.yml",
"variables": {
"token": "$session_token"
},
"name": "create user and check result."
}
}
]
30 changes: 30 additions & 0 deletions tests/testcases/create_user.v2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"config": {
"id": "create_user",
"variables": {
"device_sn": "TESTCASE_CREATE_XXX",
"uid": 9001
},
"output": [
"session_token"
],
"base_url": "http://127.0.0.1:5000",
"name": "create user and check result."
},
"teststeps": [
{
"testcase": "testcases/setup.yml",
"extract": [
"session_token"
],
"name": "setup and reset all (override) for $device_sn."
},
{
"testcase": "testcases/deps/check_and_create.yml",
"variables": {
"token": "$session_token"
},
"name": "create user and check result."
}
]
}
5 changes: 2 additions & 3 deletions tests/testcases/create_user.v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ config:
variables:
uid: 9001
device_sn: "TESTCASE_CREATE_XXX"
output:
export:
- session_token

teststeps:
-
name: setup and reset all (override) for $device_sn.
testcase: testcases/setup.yml
output:
extract:
- session_token

-
name: create user and check result.
variables:
Expand Down
4 changes: 2 additions & 2 deletions tests/testcases/create_user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
variables:
uid: 9001
device_sn: "TESTCASE_CREATE_XXX"
output:
export:
- session_token

- test:
name: setup and reset all (override) for $device_sn.
testcase: testcases/setup.yml
output:
extract:
- session_token

- test:
Expand Down
2 changes: 1 addition & 1 deletion tests/testcases/setup.v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ config:
app_version: '2.8.6'
base_url: "http://127.0.0.1:5000"
verify: False
output:
export:
- session_token

teststeps:
Expand Down
2 changes: 1 addition & 1 deletion tests/testcases/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
app_version: '2.8.6'
base_url: "http://127.0.0.1:5000"
verify: False
output:
export:
- session_token

- test:
Expand Down

0 comments on commit 3b4587d

Please sign in to comment.