背景
在yaml文件里面提取request放入缓存时,request是form-data,错用jsonpath提取并写入缓存,导致后面的所有运行都异常
原因
起因是我想引用请求体的Uid,提取方式用错了,所以可以看到最后一段current_request_set_cache写入的value值无效
formData:'{"Uid": "0000test0000","ReId": "222255","Number":"","Title":"IsATile"}'
current_request_set_cache:type: requestjsonpath: $.data[0].IDname: new_ID
这也就导致了直接异常,erro产生
执行用例池写入
ImportError while loading conftest 'D:\A_Soft_Test\autotest (2)\test_case\conftest.py'.
..\__init__.py:36: in <module>write_case_process()
..\__init__.py:19: in write_case_processcase_process = CaseData(i).case_process(case_id_switch=True)
..\..\utils\files\get_yaml_data_analysis.py:128: in case_processcase_list.append({key: TestCase(**case_date).dict()})
..\..\venv\lib\site-packages\pydantic\main.py:406: in __init__raise validation_error
E pydantic.error_wrappers.ValidationError: 1 validation error for TestCase
E current_request_set_cache
E value is not a valid list (type=type_error.list)Process finished with exit code 4Empty suite
解决方案
1. 清理缓存,咸亨叙事直接读取cache,所以就算改了代码也没用,
删除__pycache__
或临时文件后重新运行
2. 清理python解释器缓存
find . -name "*.pyc" -delete # Linux/Mac
del /s *.pyc # Windows
这两种方式我试了都无效,所以我的解决方案是:
4. 删掉项目的venv文件,重新创建和安装依赖包
# 进入项目目录,创建venv
python -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
最后一些收获
在需依赖的case中 current_request_set_cache:- type: requestjsonpath: $.Uidname: new_Uid# 与在依赖的case中,等价dependence_case: truedependence_case_data:- case_id: s_id_contract # 编号查出合同IDdependent_data:- dependent_type: responsejsonpath: $.data[0].IDset_cache: new_ID