diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d6f55e08..10e819d7 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 3.0.9 (2020-06-05) +## 3.0.9 (2020-06-07) **Fixed** diff --git a/examples/httpbin/basic_test.py b/examples/httpbin/basic_test.py index b74d7c1d..bfa47499 100644 --- a/examples/httpbin/basic_test.py +++ b/examples/httpbin/basic_test.py @@ -1,4 +1,4 @@ -# NOTICE: Generated By HttpRunner v3.0.9 +# NOTE: Generated By HttpRunner v3.0.9 # FROM: examples/httpbin/basic.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/httpbin/hooks_test.py b/examples/httpbin/hooks_test.py index aeb92dd3..cec6ad42 100644 --- a/examples/httpbin/hooks_test.py +++ b/examples/httpbin/hooks_test.py @@ -1,4 +1,4 @@ -# NOTICE: Generated By HttpRunner v3.0.9 +# NOTE: Generated By HttpRunner v3.0.9 # FROM: examples/httpbin/hooks.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/httpbin/load_image_test.py b/examples/httpbin/load_image_test.py index 16a9044c..cca17a7c 100644 --- a/examples/httpbin/load_image_test.py +++ b/examples/httpbin/load_image_test.py @@ -1,4 +1,4 @@ -# NOTICE: Generated By HttpRunner v3.0.9 +# NOTE: Generated By HttpRunner v3.0.9 # FROM: examples/httpbin/load_image.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/httpbin/upload_test.py b/examples/httpbin/upload_test.py index d89d30f9..6ed390a8 100644 --- a/examples/httpbin/upload_test.py +++ b/examples/httpbin/upload_test.py @@ -1,4 +1,4 @@ -# NOTICE: Generated By HttpRunner v3.0.9 +# NOTE: Generated By HttpRunner v3.0.9 # FROM: examples/httpbin/upload.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/httpbin/validate_test.py b/examples/httpbin/validate_test.py index 8e7d8618..093d5075 100644 --- a/examples/httpbin/validate_test.py +++ b/examples/httpbin/validate_test.py @@ -1,4 +1,4 @@ -# NOTICE: Generated By HttpRunner v3.0.9 +# NOTE: Generated By HttpRunner v3.0.9 # FROM: examples/httpbin/validate.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_functions_test.py b/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_functions_test.py index 474e99c2..acb70cd0 100644 --- a/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_functions_test.py +++ b/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_functions_test.py @@ -1,4 +1,4 @@ -# NOTICE: Generated By HttpRunner v3.0.9 +# NOTE: Generated By HttpRunner v3.0.9 # FROM: examples/postman_echo/request_methods/request_with_functions.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py b/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py index 35a113d2..294df37f 100644 --- a/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py +++ b/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py @@ -1,4 +1,4 @@ -# NOTICE: Generated By HttpRunner v3.0.9 +# NOTE: Generated By HttpRunner v3.0.9 # FROM: examples/postman_echo/request_methods/request_with_testcase_reference.yml import os diff --git a/examples/postman_echo/request_methods/hardcode_test.py b/examples/postman_echo/request_methods/hardcode_test.py index a499659b..ffa7d91a 100644 --- a/examples/postman_echo/request_methods/hardcode_test.py +++ b/examples/postman_echo/request_methods/hardcode_test.py @@ -1,4 +1,4 @@ -# NOTICE: Generated By HttpRunner v3.0.9 +# NOTE: Generated By HttpRunner v3.0.9 # FROM: examples/postman_echo/request_methods/hardcode.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/postman_echo/request_methods/request_with_functions_test.py b/examples/postman_echo/request_methods/request_with_functions_test.py index 340749f5..159d93b6 100644 --- a/examples/postman_echo/request_methods/request_with_functions_test.py +++ b/examples/postman_echo/request_methods/request_with_functions_test.py @@ -1,4 +1,4 @@ -# NOTICE: Generated By HttpRunner v3.0.9 +# NOTE: Generated By HttpRunner v3.0.9 # FROM: examples/postman_echo/request_methods/request_with_functions.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/postman_echo/request_methods/request_with_testcase_reference_test.py b/examples/postman_echo/request_methods/request_with_testcase_reference_test.py index 75c211ff..ece17405 100644 --- a/examples/postman_echo/request_methods/request_with_testcase_reference_test.py +++ b/examples/postman_echo/request_methods/request_with_testcase_reference_test.py @@ -1,4 +1,4 @@ -# NOTICE: Generated By HttpRunner v3.0.9 +# NOTE: Generated By HttpRunner v3.0.9 # FROM: examples/postman_echo/request_methods/request_with_testcase_reference.yml import os diff --git a/examples/postman_echo/request_methods/request_with_variables_test.py b/examples/postman_echo/request_methods/request_with_variables_test.py index 47eff628..aab91e97 100644 --- a/examples/postman_echo/request_methods/request_with_variables_test.py +++ b/examples/postman_echo/request_methods/request_with_variables_test.py @@ -1,4 +1,4 @@ -# NOTICE: Generated By HttpRunner v3.0.9 +# NOTE: Generated By HttpRunner v3.0.9 # FROM: examples/postman_echo/request_methods/request_with_variables.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/postman_echo/request_methods/validate_with_functions_test.py b/examples/postman_echo/request_methods/validate_with_functions_test.py index b077ebc8..5a730f1e 100644 --- a/examples/postman_echo/request_methods/validate_with_functions_test.py +++ b/examples/postman_echo/request_methods/validate_with_functions_test.py @@ -1,4 +1,4 @@ -# NOTICE: Generated By HttpRunner v3.0.9 +# NOTE: Generated By HttpRunner v3.0.9 # FROM: examples/postman_echo/request_methods/validate_with_functions.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/examples/postman_echo/request_methods/validate_with_variables_test.py b/examples/postman_echo/request_methods/validate_with_variables_test.py index c333f462..26c2467f 100644 --- a/examples/postman_echo/request_methods/validate_with_variables_test.py +++ b/examples/postman_echo/request_methods/validate_with_variables_test.py @@ -1,4 +1,4 @@ -# NOTICE: Generated By HttpRunner v3.0.9 +# NOTE: Generated By HttpRunner v3.0.9 # FROM: examples/postman_echo/request_methods/validate_with_variables.yml from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase diff --git a/httprunner/cli.py b/httprunner/cli.py index 7786f43e..c7f89910 100644 --- a/httprunner/cli.py +++ b/httprunner/cli.py @@ -1,4 +1,5 @@ import argparse +import enum import os import sys @@ -23,7 +24,7 @@ def init_parser_run(subparsers): return sub_parser_run -def main_run(extra_args): +def main_run(extra_args) -> enum.IntEnum: capture_message("start to run") # keep compatibility with v2 extra_args = ensure_cli_args(extra_args) @@ -52,7 +53,7 @@ def main_run(extra_args): extra_args_new.append("--tb=short") extra_args_new.extend(testcase_path_list) - sys.exit(pytest.main(extra_args_new)) + return pytest.main(extra_args_new) def main(): @@ -112,7 +113,7 @@ def main(): sys.exit(0) if sys.argv[1] == "run": - main_run(extra_args) + sys.exit(main_run(extra_args)) elif sys.argv[1] == "startproject": main_scaffold(args) elif sys.argv[1] == "har2case": diff --git a/httprunner/make.py b/httprunner/make.py index ede80460..5ddc22b6 100644 --- a/httprunner/make.py +++ b/httprunner/make.py @@ -29,7 +29,7 @@ pytest_files_made_cache_mapping: Dict[Text, Text] = {} pytest_files_run_set: Set = set() __TEMPLATE__ = jinja2.Template( - """# NOTICE: Generated By HttpRunner v{{ version }} + """# NOTE: Generated By HttpRunner v{{ version }} # FROM: {{ testcase_path }} {% if imports_list %} import os diff --git a/tests/data/a-b.c/1.yml b/tests/data/a-b.c/1.yml new file mode 100644 index 00000000..ffb63d09 --- /dev/null +++ b/tests/data/a-b.c/1.yml @@ -0,0 +1,30 @@ +config: + name: "request methods testcase with functions" + variables: + foo1: session_bar1 + base_url: "https://postman-echo.com" + verify: False + +teststeps: +- + name: get with params + variables: + foo1: bar1 + foo2: session_bar2 + sum_v: "${sum_two(1, 2)}" + request: + method: GET + url: /get + params: + foo1: $foo1 + foo2: $foo2 + sum_v: $sum_v + headers: + User-Agent: HttpRunner/${get_httprunner_version()} + extract: + session_foo2: "body.args.foo2" + validate: + - eq: ["status_code", 200] + - eq: ["body.args.foo1", "session_bar1"] + - eq: ["body.args.sum_v", "3"] + - eq: ["body.args.foo2", "session_bar2"] diff --git a/tests/data/a-b.c/2 3.yml b/tests/data/a-b.c/2 3.yml new file mode 100644 index 00000000..ef4961ed --- /dev/null +++ b/tests/data/a-b.c/2 3.yml @@ -0,0 +1,30 @@ +config: + name: "reference testcase unittest for abnormal folder path" + variables: + foo1: session_bar1 + base_url: "https://postman-echo.com" + verify: False + +teststeps: +- + name: request with functions + variables: + foo1: override_bar1 + testcase: 1.yml + export: + - session_foo2 +- + name: post form data + variables: + foo1: bar1 + request: + method: POST + url: /post + headers: + User-Agent: HttpRunner/${get_httprunner_version()} + Content-Type: "application/x-www-form-urlencoded" + data: "foo1=$foo1&foo2=$session_foo2" + validate: + - eq: ["status_code", 200] + - eq: ["body.form.foo1", "session_bar1"] + - eq: ["body.form.foo2", "session_bar2"] diff --git a/tests/data/a-b.c/__init__.py b/tests/data/a-b.c/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/data/a-b.c/debugtalk.py b/tests/data/a-b.c/debugtalk.py new file mode 100644 index 00000000..af8b22eb --- /dev/null +++ b/tests/data/a-b.c/debugtalk.py @@ -0,0 +1,13 @@ +from httprunner import __version__ + + +def get_httprunner_version(): + return __version__ + + +def sum_two(m, n): + return m + n + + +def get_variables(): + return {"foo1": "session_bar1"} diff --git a/tests/runner_test.py b/tests/runner_test.py index 7c664dde..b91fd3df 100644 --- a/tests/runner_test.py +++ b/tests/runner_test.py @@ -1,6 +1,8 @@ +import os import unittest from httprunner import loader +from httprunner.cli import main_run from httprunner.runner import HttpRunner @@ -28,3 +30,11 @@ class TestHttpRunner(unittest.TestCase): self.assertEqual(result.name, "request methods testcase: reference testcase") self.assertEqual(result.step_datas[0].name, "request with functions") self.assertEqual(len(result.step_datas), 2) + + def test_run_testcase_with_abnormal_path(self): + exit_code = main_run(["tests/data/a-b.c/2 3.yml"]) + self.assertEqual(exit_code, 0) + self.assertTrue(os.path.exists("tests/data/a_b_c/__init__.py")) + self.assertTrue(os.path.exists("tests/data/a_b_c/debugtalk.py")) + self.assertTrue(os.path.exists("tests/data/a_b_c/T1_test.py")) + self.assertTrue(os.path.exists("tests/data/a_b_c/T2_3_test.py")) diff --git a/tests/utils_test.py b/tests/utils_test.py index 2a01c08a..b15a5c7f 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -101,24 +101,16 @@ class TestUtils(unittest.TestCase): def test_ensure_file_path_valid(self): self.assertEqual( - ensure_file_path_valid( - "examples/a-b.c/d f/hardcode.yml" - ), - os.path.join( - os.getcwd(), "examples/a_b_c/d_f/hardcode.yml" - ), + ensure_file_path_valid("examples/a-b.c/d f/hardcode.yml"), + os.path.join(os.getcwd(), "examples/a_b_c/d_f/hardcode.yml"), ) self.assertEqual( ensure_file_path_valid("1/2B/3.yml"), os.path.join(os.getcwd(), "T1/T2B/T3.yml"), ) self.assertEqual( - ensure_file_path_valid( - "examples/a-b.c/2B/hardcode.yml" - ), - os.path.join( - os.getcwd(), "examples/a_b_c/T2B/hardcode.yml" - ), + ensure_file_path_valid("examples/a-b.c/2B/hardcode.yml"), + os.path.join(os.getcwd(), "examples/a_b_c/T2B/hardcode.yml"), ) self.assertEqual( ensure_file_path_valid("examples/postman_echo/request_methods/"),