From c47442b67a5b9eb2d3feda5205ffc0bd57cea003 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 12 Dec 2019 22:51:40 +0800 Subject: [PATCH 1/4] docs: update installation for developers --- docs/Installation.md | 63 ++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/docs/Installation.md b/docs/Installation.md index 16f1d750..9cbe45d0 100644 --- a/docs/Installation.md +++ b/docs/Installation.md @@ -2,7 +2,7 @@ HttpRunner 是一个基于 Python 开发的测试框架,可以运行在 macOS、Linux、Windows 系统平台上。 -**Python 版本**:HttpRunner 支持 Python 3.4 及以上的所有版本,并使用 Travis-CI 进行了[持续集成测试][travis-ci],测试覆盖的版本包括 2.7/3.4/3.5/3.6/3.7。虽然 HttpRunner 暂时保留了对 Python 2.7 的兼容支持,但强烈建议使用 Python 3.4 及以上版本。 +**Python 版本**:HttpRunner 支持 Python 3.5 及以上的所有版本,并使用 Travis-CI 进行了[持续集成测试][travis-ci],测试覆盖的版本包括 2.7/3.5/3.6/3.7/3.8。虽然 HttpRunner 暂时保留了对 Python 2.7 的兼容支持,但强烈建议使用 Python 3.6 及以上版本。 **操作系统**:推荐使用 macOS/Linux。 @@ -45,10 +45,10 @@ httprunner、hrun、ate 三个命令完全等价,功能特性完全相同, ```text $ hrun -V -2.0.2 +2.4.1 $ har2case -V -0.2.0 +0.3.1 ``` ## 开发者模式 @@ -57,10 +57,10 @@ $ har2case -V 如果你不仅仅是使用 HttpRunner,还需要对 HttpRunner 进行开发调试(debug),那么就需要进行如下操作。 -HttpRunner 使用 [pipenv][pipenv] 对依赖包进行管理,若你还没有安装 pipenv,需要先执行如下命令进行按照: +HttpRunner 使用 [poetry][poetry] 对依赖包进行管理,若你还没有安装 poetry,需要先执行如下命令进行按照: ```bash -$ pip install pipenv +$ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python ``` 获取 HttpRunner 源码: @@ -72,49 +72,50 @@ $ git clone https://github.com/HttpRunner/HttpRunner.git 进入仓库目录,安装所有依赖: ```bash -$ pipenv install --dev +$ poetry install ``` 运行单元测试,若测试全部通过,则说明环境正常。 ```bash -$ pipenv run python -m unittest discover +$ poetry run python -m unittest discover ``` 查看 HttpRunner 的依赖情况: ```text -$ pipenv graph - -HttpRunner==2.0.0 - - colorama [required: Any, installed: 0.4.0] - - colorlog [required: Any, installed: 3.1.4] - - har2case [required: Any, installed: 0.2.0] - - PyYAML [required: Any, installed: 3.13] - - Jinja2 [required: Any, installed: 2.10] - - MarkupSafe [required: >=0.23, installed: 1.0] - - PyYAML [required: Any, installed: 3.13] - - requests [required: Any, installed: 2.20.0] - - certifi [required: >=2017.4.17, installed: 2018.10.15] - - chardet [required: >=3.0.2,<3.1.0, installed: 3.0.4] - - idna [required: >=2.5,<2.8, installed: 2.7] - - urllib3 [required: >=1.21.1,<1.25, installed: 1.24] - - requests-toolbelt [required: Any, installed: 0.8.0] - - requests [required: >=2.0.1,<3.0.0, installed: 2.20.0] - - certifi [required: >=2017.4.17, installed: 2018.10.15] - - chardet [required: >=3.0.2,<3.1.0, installed: 3.0.4] - - idna [required: >=2.5,<2.8, installed: 2.7] - - urllib3 [required: >=1.21.1,<1.25, installed: 1.24] +$ poetry show +certifi 2019.9.11 Python package for providing Mozilla's CA Bundle. +chardet 3.0.4 Universal encoding detector for Python 2 and 3 +click 7.0 Composable command line interface toolkit +colorama 0.4.1 Cross-platform colored terminal text. +colorlog 4.0.2 Log formatting with colors! +coverage 4.5.4 Code coverage measurement for Python +coveralls 1.8.2 Show coverage stats online via coveralls.io +docopt 0.6.2 Pythonic argument parser, that will make you smile +filetype 1.0.5 Infer file type and MIME type of any file/buffer. No external dependencies. +flask 0.12.4 A microframework based on Werkzeug, Jinja2 and good intentions +har2case 0.3.1 Convert HAR(HTTP Archive) to YAML/JSON testcases for HttpRunner. +idna 2.8 Internationalized Domain Names in Applications (IDNA) +itsdangerous 1.1.0 Various helpers to pass data to untrusted environments and back. +jinja2 2.10.3 A very fast and expressive template engine. +jsonpath 0.82 An XPath for JSON +markupsafe 1.1.1 Safely add untrusted strings to HTML/XML markup. +pyyaml 5.1.2 YAML parser and emitter for Python +requests 2.22.0 Python HTTP for Humans. +requests-toolbelt 0.9.1 A utility belt for advanced users of python-requests +urllib3 1.25.6 HTTP library with thread-safe connection pooling, file post, and more. +werkzeug 0.16.0 The comprehensive WSGI web application library. ``` 调试运行方式: ```bash # 调试运行 hrun -$ pipenv run python main-debug.py hrun -h +$ poetry run python -m httprunner -h # 调试运行 locusts -$ pipenv run python main-debug.py locusts -h +$ pipenv run python -m httprunner.plugins.locusts -h ``` ## Docker @@ -124,4 +125,4 @@ TODO [travis-ci]: https://travis-ci.org/HttpRunner/HttpRunner [Locust]: http://locust.io/ [har2case]: https://github.com/HttpRunner/har2case -[pipenv]: https://docs.pipenv.org/ \ No newline at end of file +[poetry]: https://github.com/sdispater/poetry \ No newline at end of file From 9b5f1506041b66f470f8bd7ef613e6d3ae7f286d Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 13 Dec 2019 10:38:30 +0800 Subject: [PATCH 2/4] refactor: rename plugin to extention, httprunner/plugins -> httprunner/ext --- httprunner/{plugins => ext}/__init__.py | 2 +- httprunner/{plugins => ext}/locusts/README.md | 0 httprunner/{plugins => ext}/locusts/__init__.py | 0 httprunner/ext/locusts/__main__.py | 4 ++++ httprunner/{plugins => ext}/locusts/cli.py | 0 httprunner/{plugins => ext}/locusts/locustfile_template.py | 2 +- httprunner/{plugins => ext}/locusts/utils.py | 0 httprunner/{plugins => ext}/uploader/__init__.py | 6 +++--- httprunner/parser.py | 6 +++--- httprunner/plugins/locusts/__main__.py | 4 ---- tests/{test_plugins => test_extension}/__init__.py | 0 tests/{test_plugins => test_extension}/test_locusts.py | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) rename httprunner/{plugins => ext}/__init__.py (64%) rename httprunner/{plugins => ext}/locusts/README.md (100%) rename httprunner/{plugins => ext}/locusts/__init__.py (100%) create mode 100644 httprunner/ext/locusts/__main__.py rename httprunner/{plugins => ext}/locusts/cli.py (100%) rename httprunner/{plugins => ext}/locusts/locustfile_template.py (94%) rename httprunner/{plugins => ext}/locusts/utils.py (100%) rename httprunner/{plugins => ext}/uploader/__init__.py (95%) delete mode 100644 httprunner/plugins/locusts/__main__.py rename tests/{test_plugins => test_extension}/__init__.py (100%) rename tests/{test_plugins => test_extension}/test_locusts.py (89%) diff --git a/httprunner/plugins/__init__.py b/httprunner/ext/__init__.py similarity index 64% rename from httprunner/plugins/__init__.py rename to httprunner/ext/__init__.py index 1802047f..2ce5da7e 100644 --- a/httprunner/plugins/__init__.py +++ b/httprunner/ext/__init__.py @@ -1,2 +1,2 @@ # NOTICE: -# This file should not be deleted, or ImportError will be raised in Python 2.7 when importing plugin +# This file should not be deleted, or ImportError will be raised in Python 2.7 when importing extension diff --git a/httprunner/plugins/locusts/README.md b/httprunner/ext/locusts/README.md similarity index 100% rename from httprunner/plugins/locusts/README.md rename to httprunner/ext/locusts/README.md diff --git a/httprunner/plugins/locusts/__init__.py b/httprunner/ext/locusts/__init__.py similarity index 100% rename from httprunner/plugins/locusts/__init__.py rename to httprunner/ext/locusts/__init__.py diff --git a/httprunner/ext/locusts/__main__.py b/httprunner/ext/locusts/__main__.py new file mode 100644 index 00000000..bc8d706f --- /dev/null +++ b/httprunner/ext/locusts/__main__.py @@ -0,0 +1,4 @@ +from httprunner.ext.locusts.cli import main + +if __name__ == "__main__": + main() diff --git a/httprunner/plugins/locusts/cli.py b/httprunner/ext/locusts/cli.py similarity index 100% rename from httprunner/plugins/locusts/cli.py rename to httprunner/ext/locusts/cli.py diff --git a/httprunner/plugins/locusts/locustfile_template.py b/httprunner/ext/locusts/locustfile_template.py similarity index 94% rename from httprunner/plugins/locusts/locustfile_template.py rename to httprunner/ext/locusts/locustfile_template.py index 72697cfa..1ad06eb7 100644 --- a/httprunner/plugins/locusts/locustfile_template.py +++ b/httprunner/ext/locusts/locustfile_template.py @@ -5,7 +5,7 @@ from locust import HttpLocust, TaskSet, task from locust.events import request_failure from httprunner.exceptions import MyBaseError, MyBaseFailure -from httprunner.plugins.locusts.utils import prepare_locust_tests +from httprunner.ext.locusts.utils import prepare_locust_tests from httprunner.runner import Runner logging.getLogger().setLevel(logging.CRITICAL) diff --git a/httprunner/plugins/locusts/utils.py b/httprunner/ext/locusts/utils.py similarity index 100% rename from httprunner/plugins/locusts/utils.py rename to httprunner/ext/locusts/utils.py diff --git a/httprunner/plugins/uploader/__init__.py b/httprunner/ext/uploader/__init__.py similarity index 95% rename from httprunner/plugins/uploader/__init__.py rename to httprunner/ext/uploader/__init__.py index b432a1a6..404d635b 100644 --- a/httprunner/plugins/uploader/__init__.py +++ b/httprunner/ext/uploader/__init__.py @@ -1,6 +1,6 @@ -""" upload test plugin. +""" upload test extension. -If you want to use this plugin, you should install the following dependencies first. +If you want to use this extension, you should install the following dependencies first. - requests_toolbelt - filetype @@ -50,7 +50,7 @@ try: from requests_toolbelt import MultipartEncoder except ImportError: msg = """ -uploader plugin dependencies uninstalled, install first and try again. +uploader extension dependencies uninstalled, install first and try again. install with pip: $ pip install requests_toolbelt filetype """ diff --git a/httprunner/parser.py b/httprunner/parser.py index cc6f13aa..ed642d0c 100644 --- a/httprunner/parser.py +++ b/httprunner/parser.py @@ -429,8 +429,8 @@ def get_mapping_function(function_name, functions_mapping): return utils.get_os_environ elif function_name in ["multipart_encoder", "multipart_content_type"]: - # plugin for upload test - from httprunner.plugins import uploader + # extension for upload test + from httprunner.ext import uploader return getattr(uploader, function_name) try: @@ -1158,7 +1158,7 @@ def __prepare_testcase_tests(tests, config, project_mapping, session_variables_s test_dict["request"]["verify"] = config_verify if "upload" in test_dict["request"]: - from httprunner.plugins.uploader import prepare_upload_test + from httprunner.ext.uploader import prepare_upload_test prepare_upload_test(test_dict) # current teststep variables diff --git a/httprunner/plugins/locusts/__main__.py b/httprunner/plugins/locusts/__main__.py deleted file mode 100644 index dbf8961f..00000000 --- a/httprunner/plugins/locusts/__main__.py +++ /dev/null @@ -1,4 +0,0 @@ -from httprunner.plugins.locusts.cli import main - -if __name__ == "__main__": - main() diff --git a/tests/test_plugins/__init__.py b/tests/test_extension/__init__.py similarity index 100% rename from tests/test_plugins/__init__.py rename to tests/test_extension/__init__.py diff --git a/tests/test_plugins/test_locusts.py b/tests/test_extension/test_locusts.py similarity index 89% rename from tests/test_plugins/test_locusts.py rename to tests/test_extension/test_locusts.py index f838d05e..59d957ff 100644 --- a/tests/test_plugins/test_locusts.py +++ b/tests/test_extension/test_locusts.py @@ -1,7 +1,7 @@ import os import unittest -from httprunner.plugins.locusts.utils import prepare_locust_tests +from httprunner.ext.locusts.utils import prepare_locust_tests class TestLocust(unittest.TestCase): From 0a4a8188cd9c610ac13447cdf22441bf6cadd500 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 13 Dec 2019 11:17:26 +0800 Subject: [PATCH 3/4] refactor: replace with open file handler, avoid reading files into memory --- docs/CHANGELOG.md | 6 ++++++ httprunner/__init__.py | 2 +- httprunner/ext/uploader/__init__.py | 7 ++++--- pyproject.toml | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d5a4b732..1d8c8f18 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 2.4.2 (2019-12-13) + +**Changed** + +- refactor: replace with open file handler, avoid reading files into memory + ## 2.4.1 (2019-12-12) **Added** diff --git a/httprunner/__init__.py b/httprunner/__init__.py index ef6aac10..8be0e197 100644 --- a/httprunner/__init__.py +++ b/httprunner/__init__.py @@ -1,4 +1,4 @@ -__version__ = "2.4.1" +__version__ = "2.4.2" __description__ = "One-stop solution for HTTP(S) testing." __all__ = ["__version__", "__description__"] diff --git a/httprunner/ext/uploader/__init__.py b/httprunner/ext/uploader/__init__.py index 404d635b..fb299b1d 100644 --- a/httprunner/ext/uploader/__init__.py +++ b/httprunner/ext/uploader/__init__.py @@ -128,9 +128,10 @@ def multipart_encoder(**kwargs): if is_exists_file: # value is file path to upload filename = os.path.basename(_file_path) - with open(_file_path, 'rb') as f: - mime_type = get_filetype(_file_path) - fields_dict[key] = (filename, f.read(), mime_type) + mime_type = get_filetype(_file_path) + # TODO: fix ResourceWarning for unclosed file + file_handler = open(_file_path, 'rb') + fields_dict[key] = (filename, file_handler, mime_type) else: fields_dict[key] = value diff --git a/pyproject.toml b/pyproject.toml index 168a025b..3bbc6e33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "httprunner" -version = "2.4.1" +version = "2.4.2" description = "One-stop solution for HTTP(S) testing." license = "Apache-2.0" readme = "README.md" From c53493c2a1dfe10eade6225500f1252f96711a8e Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 13 Dec 2019 12:06:46 +0800 Subject: [PATCH 4/4] docs: update changelog --- docs/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1d8c8f18..fe235dce 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,6 +5,8 @@ **Changed** - refactor: replace with open file handler, avoid reading files into memory +- refactor: rename plugin to extension, httprunner/plugins -> httprunner/ext +- docs: update installation doc for developers ## 2.4.1 (2019-12-12)