python写一个读取excel文件用例通过jira接口向里面导入用例实例
时间: 2024-05-24 17:04:43 浏览: 188
好的,以下是一个示例代码,需要安装 openpyxl、jira 模块:
```python
import openpyxl
from jira import JIRA
# 读取Excel文件
workbook = openpyxl.load_workbook('test_cases.xlsx')
sheet = workbook.active
# 连接到Jira服务器
jira = JIRA('https://your-jira-url.com', basic_auth=('username', 'password'))
# 遍历Excel文件中的测试用例
for row in sheet.iter_rows(min_row=2):
# 从Excel表格中获取测试用例字段
summary = row[1].value
description = row[2].value
priority = row[3].value
components = row[4].value.split(',')
labels = row[5].value.split(',')
steps = row[6].value
expected_result = row[7].value
# 创建Jira Issue,并添加测试用例相关信息
new_issue = jira.create_issue(project='YOUR-PROJECT-KEY', summary=summary, description=description, issuetype={'name': 'Test Case'}, priority={'name': priority})
new_issue.fields.components = [{'name': c} for c in components]
new_issue.fields.labels = labels
# 添加测试用例步骤
step_list = []
for step in steps.split('\n'):
step_list.append({'step': step})
new_issue.fields.customfield_10004 = step_list
# 添加期望结果
new_issue.fields.customfield_10005 = expected_result
# 提交到Jira服务器
new_issue.update()
```
以上代码仅供参考,需要根据实际情况进行调整。
阅读全文