fix: ensure upload ready

This commit is contained in:
debugtalk
2020-06-07 17:17:52 +08:00
parent 31f5cfa9df
commit 012194d788
4 changed files with 27 additions and 13 deletions
+4
View File
@@ -6,6 +6,10 @@
- feat: implement step setup/teardown hooks - feat: implement step setup/teardown hooks
**Fixed**
- fix: ensure upload ready
## 3.0.9 (2020-06-07) ## 3.0.9 (2020-06-07)
**Fixed** **Fixed**
+1 -1
View File
@@ -1,4 +1,4 @@
__version__ = "3.0.9" __version__ = "3.0.10"
__description__ = "One-stop solution for HTTP(S) testing." __description__ = "One-stop solution for HTTP(S) testing."
from httprunner.runner import HttpRunner from httprunner.runner import HttpRunner
+19 -9
View File
@@ -60,6 +60,22 @@ except ModuleNotFoundError:
UPLOAD_READY = False 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": def prepare_upload_step(step: TStep, functions: FunctionsMapping) -> "NoReturn":
""" preprocess for upload test """ preprocess for upload test
replace `upload` info with MultipartEncoder replace `upload` info with MultipartEncoder
@@ -86,15 +102,7 @@ def prepare_upload_step(step: TStep, functions: FunctionsMapping) -> "NoReturn":
if not step.request.upload: if not step.request.upload:
return return
if not UPLOAD_READY: ensure_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)
params_list = [] params_list = []
for key, value in step.request.upload.items(): for key, value in step.request.upload.items():
step.variables[key] = value step.variables[key] = value
@@ -126,6 +134,7 @@ def multipart_encoder(**kwargs):
else: else:
return "text/html" return "text/html"
ensure_upload_ready()
fields_dict = {} fields_dict = {}
for key, value in kwargs.items(): for key, value in kwargs.items():
@@ -165,4 +174,5 @@ def multipart_content_type(m_encoder) -> Text:
content type content type
""" """
ensure_upload_ready()
return m_encoder.content_type return m_encoder.content_type
+3 -3
View File
@@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "httprunner" name = "httprunner"
version = "3.0.9" version = "3.0.10"
description = "One-stop solution for HTTP(S) testing." description = "One-stop solution for HTTP(S) testing."
license = "Apache-2.0" license = "Apache-2.0"
readme = "README.md" readme = "README.md"
@@ -44,8 +44,8 @@ requests-toolbelt = {version = "^0.9.1", optional = true}
filetype = {version = "^1.0.7", optional = true} filetype = {version = "^1.0.7", optional = true}
[tool.poetry.extras] [tool.poetry.extras]
allure = ["allure-pytest"] # poetry install -E allure allure = ["allure-pytest"] # pip install "httprunner[allure]", poetry install -E allure
upload = ["requests-toolbelt", "filetype"] # poetry install -E upload upload = ["requests-toolbelt", "filetype"] # pip install "httprunner[upload]", poetry install -E upload
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
coverage = "^4.5.4" coverage = "^4.5.4"