refactor: replace with open file handler, avoid reading files into memory

This commit is contained in:
debugtalk
2019-12-13 11:17:26 +08:00
parent 9b5f150604
commit 0a4a8188cd
4 changed files with 12 additions and 5 deletions

View File

@@ -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**

View File

@@ -1,4 +1,4 @@
__version__ = "2.4.1"
__version__ = "2.4.2"
__description__ = "One-stop solution for HTTP(S) testing."
__all__ = ["__version__", "__description__"]

View File

@@ -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

View File

@@ -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"