mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-21 12:33:59 +08:00
fix #418: deepcopy testcase when testcase contains BufferReader
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
# encoding: utf-8
|
||||
|
||||
import ast
|
||||
import copy
|
||||
import os
|
||||
import re
|
||||
|
||||
@@ -601,7 +600,6 @@ def parse_tests(testcases, variables_mapping=None):
|
||||
list: parsed testcases list, with config variables/parameters/name/request parsed.
|
||||
|
||||
"""
|
||||
# exception_stage = "parse tests"
|
||||
variables_mapping = variables_mapping or {}
|
||||
parsed_testcases_list = []
|
||||
|
||||
@@ -629,7 +627,7 @@ def parse_tests(testcases, variables_mapping=None):
|
||||
) or [{}]
|
||||
|
||||
for parameter_mapping in cartesian_product_parameters_list:
|
||||
testcase_dict = copy.deepcopy(testcase)
|
||||
testcase_dict = utils.deepcopy_dict(testcase)
|
||||
config = testcase_dict.get("config")
|
||||
|
||||
# parse config variables
|
||||
|
||||
@@ -203,6 +203,42 @@ def convert_mappinglist_to_orderdict(mapping_list):
|
||||
return ordered_dict
|
||||
|
||||
|
||||
def deepcopy_dict(data):
|
||||
""" deepcopy dict data, ignore file object (_io.BufferedReader)
|
||||
|
||||
Args:
|
||||
data (dict): dict data structure
|
||||
{
|
||||
'a': 1,
|
||||
'b': [2, 4],
|
||||
'c': lambda x: x+1,
|
||||
'd': open('LICENSE'),
|
||||
'f': {
|
||||
'f1': {'a1': 2},
|
||||
'f2': io.open('LICENSE', 'rb'),
|
||||
}
|
||||
}
|
||||
|
||||
Returns:
|
||||
dict: deep copied dict data, with file object unchanged.
|
||||
|
||||
"""
|
||||
try:
|
||||
return copy.deepcopy(data)
|
||||
except TypeError:
|
||||
copied_data = {}
|
||||
for key, value in data.items():
|
||||
if isinstance(value, dict):
|
||||
copied_data[key] = deepcopy_dict(value)
|
||||
else:
|
||||
try:
|
||||
copied_data[key] = copy.deepcopy(value)
|
||||
except TypeError:
|
||||
copied_data[key] = value
|
||||
|
||||
return copied_data
|
||||
|
||||
|
||||
def update_ordered_dict(ordered_dict, override_mapping):
|
||||
""" override ordered_dict with new mapping.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user