diff --git a/HISTORY.md b/HISTORY.md index d8b9072e..590f10a2 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,16 @@ # Release History +## 2.0.6 (2019-03-18) + +**Features** + +- create .gitignore file when initializing new project + +**Bugfixes** + +- fix CSV relative path detection +- fix current validators displaying the former one when they are empty + ## 2.0.5 (2019-03-04) **Features** diff --git a/httprunner/__about__.py b/httprunner/__about__.py index 952b6b7c..5f7b3a5e 100644 --- a/httprunner/__about__.py +++ b/httprunner/__about__.py @@ -1,7 +1,7 @@ __title__ = 'HttpRunner' __description__ = 'One-stop solution for HTTP(S) testing.' __url__ = 'https://github.com/HttpRunner/HttpRunner' -__version__ = '2.0.5' +__version__ = '2.0.6' __author__ = 'debugtalk' __author_email__ = 'mail@debugtalk.com' __license__ = 'Apache-2.0' diff --git a/httprunner/exceptions.py b/httprunner/exceptions.py index 3db701ee..787e864d 100644 --- a/httprunner/exceptions.py +++ b/httprunner/exceptions.py @@ -50,6 +50,9 @@ class VariableNotFound(NotFoundError): class EnvNotFound(NotFoundError): pass +class CSVNotFound(NotFoundError): + pass + class ApiNotFound(NotFoundError): pass diff --git a/httprunner/loader.py b/httprunner/loader.py index daec7c4b..ade04d6a 100644 --- a/httprunner/loader.py +++ b/httprunner/loader.py @@ -80,6 +80,15 @@ def load_csv_file(csv_file): ] """ + if not os.path.isabs(csv_file): + project_working_directory = tests_def_mapping["PWD"] or os.getcwd() + # make compatible with Windows/Linux + csv_file = os.path.join(project_working_directory, *csv_file.split("/")) + + if not os.path.isfile(csv_file): + # file path not exist + raise exceptions.CSVNotFound(csv_file) + csv_content_list = [] with io.open(csv_file, encoding='utf-8') as csvfile: diff --git a/httprunner/utils.py b/httprunner/utils.py index 79d7d130..04f4778b 100644 --- a/httprunner/utils.py +++ b/httprunner/utils.py @@ -533,6 +533,12 @@ def create_scaffold(project_name): ] [create_path(p[0], p[1]) for p in path_list] + # create .gitignore file + ignore_file = os.path.join(project_name, ".gitignore") + ignore_content = ".env\nreports/*" + with open(ignore_file, "w") as f: + f.write(ignore_content) + def gen_cartesian_product(*args): """ generate cartesian product for lists diff --git a/tests/data/demo_testcase.yml b/tests/data/demo_testcase.yml index d4f2f178..36924cf3 100644 --- a/tests/data/demo_testcase.yml +++ b/tests/data/demo_testcase.yml @@ -6,11 +6,6 @@ var_d: "${gen_random_string(5)}" var_e: $var_d PROJECT_KEY: ${ENV(PROJECT_KEY)} - # parameters: - # - "var_a-var_b": - # - [11, 21] - # - [12, 22] - # - "app_version": "${gen_app_version()}" - test: name: testcase1-$var_a diff --git a/tests/test_parser.py b/tests/test_parser.py index 497c3507..663de616 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -407,9 +407,10 @@ class TestParser(unittest.TestCase): ) def test_parse_parameters_parameterize(self): + loader.load_project_tests(os.path.join(os.getcwd(), "tests")) parameters = [ - {"app_version": "${parameterize(tests/data/app_version.csv)}"}, - {"username-password": "${parameterize(tests/data/account.csv)}"} + {"app_version": "${parameterize(data/app_version.csv)}"}, + {"username-password": "${parameterize(data/account.csv)}"} ] cartesian_product_parameters = parser.parse_parameters(parameters) self.assertEqual( @@ -424,7 +425,7 @@ class TestParser(unittest.TestCase): parameters = [ {"user_agent": ["iOS/10.1", "iOS/10.2", "iOS/10.3"]}, {"app_version": "${gen_app_version()}"}, - {"username-password": "${parameterize(tests/data/account.csv)}"} + {"username-password": "${parameterize(data/account.csv)}"} ] cartesian_product_parameters = parser.parse_parameters( parameters, functions_mapping=project_mapping["functions"]) @@ -453,8 +454,6 @@ class TestParser(unittest.TestCase): self.assertEqual(test_dict1["variables"]["var_c"], 3) self.assertEqual(test_dict1["variables"]["PROJECT_KEY"], "ABCDEFGH") self.assertEqual(test_dict1["variables"]["var_d"], test_dict1["variables"]["var_e"]) - # TODO: parameters - # self.assertEqual(len(parsed_testcases), 2 * 2) self.assertEqual(parsed_testcases[0]["config"]["name"], '1230') def test_parse_tests_override_variables(self):