From 9f140fc958cd8b5a02b5e5a0840a7106a5f649f7 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sun, 7 Jun 2020 17:14:18 +0800 Subject: [PATCH] fix: ensure upload ready --- docs/CHANGELOG.md | 4 ++++ httprunner/__init__.py | 2 +- httprunner/ext/uploader/__init__.py | 28 +++++++++++++++++++--------- pyproject.toml | 6 +++--- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4e9cc920..7209ec56 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -6,6 +6,10 @@ - feat: implement step setup/teardown hooks +**Fixed** + +- fix: ensure upload ready + ## 3.0.9 (2020-06-07) **Fixed** diff --git a/httprunner/__init__.py b/httprunner/__init__.py index 40f1a9c5..3c7e46bb 100644 --- a/httprunner/__init__.py +++ b/httprunner/__init__.py @@ -1,4 +1,4 @@ -__version__ = "3.0.9" +__version__ = "3.0.10" __description__ = "One-stop solution for HTTP(S) testing." from httprunner.runner import HttpRunner diff --git a/httprunner/ext/uploader/__init__.py b/httprunner/ext/uploader/__init__.py index 4b242502..bcefd6a8 100644 --- a/httprunner/ext/uploader/__init__.py +++ b/httprunner/ext/uploader/__init__.py @@ -60,6 +60,22 @@ except ModuleNotFoundError: UPLOAD_READY = False +def ensure_upload_ready(): + if UPLOAD_READY: + return + + msg = """ + uploader extension dependencies uninstalled, install first and try again. + install with pip: + $ pip install requests_toolbelt filetype + + or you can install httprunner with optional upload dependencies: + $ pip install "httprunner[upload]" + """ + logger.error(msg) + sys.exit(1) + + def prepare_upload_step(step: TStep, functions: FunctionsMapping) -> "NoReturn": """ preprocess for upload test replace `upload` info with MultipartEncoder @@ -86,15 +102,7 @@ def prepare_upload_step(step: TStep, functions: FunctionsMapping) -> "NoReturn": if not step.request.upload: return - if not UPLOAD_READY: - msg = """ -uploader extension dependencies uninstalled, install first and try again. -install with pip: -$ pip install requests_toolbelt filetype -""" - logger.error(msg) - sys.exit(1) - + ensure_upload_ready() params_list = [] for key, value in step.request.upload.items(): step.variables[key] = value @@ -126,6 +134,7 @@ def multipart_encoder(**kwargs): else: return "text/html" + ensure_upload_ready() fields_dict = {} for key, value in kwargs.items(): @@ -165,4 +174,5 @@ def multipart_content_type(m_encoder) -> Text: content type """ + ensure_upload_ready() return m_encoder.content_type diff --git a/pyproject.toml b/pyproject.toml index 23324ab6..548b4bcf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "httprunner" -version = "3.0.9" +version = "3.0.10" description = "One-stop solution for HTTP(S) testing." license = "Apache-2.0" readme = "README.md" @@ -44,8 +44,8 @@ requests-toolbelt = {version = "^0.9.1", optional = true} filetype = {version = "^1.0.7", optional = true} [tool.poetry.extras] -allure = ["allure-pytest"] # poetry install -E allure -upload = ["requests-toolbelt", "filetype"] # poetry install -E upload +allure = ["allure-pytest"] # pip install "httprunner[allure]", poetry install -E allure +upload = ["requests-toolbelt", "filetype"] # pip install "httprunner[upload]", poetry install -E upload [tool.poetry.dev-dependencies] coverage = "^4.5.4"