From 4595022f62862cbfb2852bbb0aa7ffc3a1b6d615 Mon Sep 17 00:00:00 2001 From: jun Date: Fri, 3 Jul 2020 10:23:10 +0800 Subject: [PATCH] fixed: #931 unit test parameters --- examples/postman_echo/debugtalk.py | 5 ++++- {tests => examples/postman_echo/request_methods}/account.csv | 3 ++- httprunner/make.py | 2 +- httprunner/models.py | 1 + httprunner/runner.py | 3 ++- tests/parser_test.py | 2 +- 6 files changed, 11 insertions(+), 5 deletions(-) rename {tests => examples/postman_echo/request_methods}/account.csv (55%) diff --git a/examples/postman_echo/debugtalk.py b/examples/postman_echo/debugtalk.py index a574ab2a..d28b829b 100644 --- a/examples/postman_echo/debugtalk.py +++ b/examples/postman_echo/debugtalk.py @@ -4,7 +4,6 @@ from httprunner import __version__ def get_httprunner_version(): return __version__ - def sum_two(m, n): return m + n @@ -15,3 +14,7 @@ def get_testcase_config_variables(): def get_testsuite_config_variables(): return {"foo1": "testsuite_config_bar1", "foo2": "testsuite_config_bar2"} + + +def get_app_version(): + return [3.1, 3.0] diff --git a/tests/account.csv b/examples/postman_echo/request_methods/account.csv similarity index 55% rename from tests/account.csv rename to examples/postman_echo/request_methods/account.csv index c3dae178..67ce22c6 100644 --- a/tests/account.csv +++ b/examples/postman_echo/request_methods/account.csv @@ -1,3 +1,4 @@ username,password test1,111111 -test2,222222 \ No newline at end of file +test2,222222 +test3,333333 \ No newline at end of file diff --git a/httprunner/make.py b/httprunner/make.py index bf3f158d..ada16813 100644 --- a/httprunner/make.py +++ b/httprunner/make.py @@ -612,7 +612,7 @@ def init_make_parser(subparsers): def make_test_start_style(config: Dict) -> Text: test_start_style = "" - if config["parameters"]: + if "parameters" in config.keys(): params = config["parameters"] test_start_style = f""" import pytest diff --git a/httprunner/models.py b/httprunner/models.py index 51264c33..04fbab23 100644 --- a/httprunner/models.py +++ b/httprunner/models.py @@ -37,6 +37,7 @@ class TConfig(BaseModel): base_url: BaseUrl = "" # Text: prepare variables in debugtalk.py, ${gen_variables()} variables: Union[VariablesMapping, Text] = {} + parameters: Union[VariablesMapping, Text] = {} # setup_hooks: Hooks = [] # teardown_hooks: Hooks = [] export: Export = [] diff --git a/httprunner/runner.py b/httprunner/runner.py index ebdc7607..d2129f03 100644 --- a/httprunner/runner.py +++ b/httprunner/runner.py @@ -435,7 +435,8 @@ class HttpRunner(object): # parse config name config_variables = self.__config.variables - config_variables.update(parametrize) + if parametrize: + config_variables.update(parametrize) config_variables.update(self.__session_variables) self.__config.name = parse_data( self.__config.name, config_variables, self.__project_meta.functions diff --git a/tests/parser_test.py b/tests/parser_test.py index 7026711b..96d3cd20 100644 --- a/tests/parser_test.py +++ b/tests/parser_test.py @@ -461,7 +461,7 @@ class TestParserBasic(unittest.TestCase): param = [ { "user_agent": ["iOS/10.1", "iOS/10.2"], - "username-password": "${parameterize(account.csv)}", + "username-password": "${parameterize(request_methods/account.csv)}", "sum": "${add_two_nums(1, 2)}", } ]