要实现每次测试完成时生成测试记录并写入Excel表格,您可以结合使用Python的pandas库来处理数据和openpyxl库来写入Excel。以下是一个简单的示例:
首先,确保已安装所需库:
bash
pip install pandas openpyxl
接着,编写如下Python脚本,用于处理测试结果并写入Excel:
python
import pandas as pd
from openpyxl import Workbook
def write_test_result_to_excel(test_result, excel_path='test_records.xlsx'):
# 定义测试结果字典结构
test_result_dict = {
'Test Name': test_result['test_name'],
'Result': 'Pass' if test_result['result'] else 'Fail',
'Failure Reason': test_result.get('failure_reason', '')
}
# 将测试结果字典转换为Series
test_series = pd.Series(test_result_dict)
# 如果Excel文件不存在,创建一个新的
if not pd.read_excel(excel_path, engine='openpyxl').empty:
# 读取现有Excel文件内容
df = pd.read_excel(excel_path, engine='openpyxl')
# 将新测试结果追加到DataFrame末尾
df = df.append(test_series, ignore_index=T

最低0.47元/天 解锁文章
800

被折叠的 条评论
为什么被折叠?



