python jira 读取表数据批量新建子任务
生活随笔
收集整理的這篇文章主要介紹了
python jira 读取表数据批量新建子任务
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
小李在Jira中處理任務時,發現一個表格數據很有趣。他決定為每一行數據創建一個新的子任務。他復制粘貼,忙得不亦樂乎。同事小張路過,好奇地問:“你在做什么?”小李得意地回答:“我在批量新建子任務,讓這些數據都活起來!”小張瞪大眼睛:“你確定這不是在玩‘俄羅斯方塊’?”
于是,有了它~
# encoding=utf-8
from jira import JIRA
from openpyxl import load_workbook
import os, pytest, traceback
jira_server = "xxxxxx"
jira_username = "xxxxx"
jira_password = "xxxxx"
file_name = 'xxxxx'
sheet_name = 'xxxx'
#獲取jira消息
def jira_info(jira_server, jira_username, jira_password):
jira = JIRA(server=jira_server, basic_auth=(jira_username, jira_password))
return jira
#讀取表數據
def get_TestExcel(file_name, sheet_name):
print("======", os.getcwd())
workbook = load_workbook(file_name)
sheet = workbook[sheet_name]
test_data = []
for i in range(2, sheet.max_row + 1):
sub_data = {}
for j in range(1, sheet.max_column + 1):
sub_data[sheet.cell(1, j).value] = sheet.cell(i, j).value
test_data.append(sub_data)
return test_data
case_data = get_TestExcel(file_name, sheet_name)
idss = ["標題: {} ".format(data["標題"]) for data in case_data]
#根據讀取數據新建任務
@pytest.mark.parametrize("test_data", case_data, ids=idss)
def test_create_task(test_data):
project_key = test_data['項目key']
summary = test_data['標題']
description = test_data['描述']
issuetype = test_data['類型id']
assignee = test_data['指向人']
parent = test_data['掛靠需求key']
test_environment_value = test_data['測試環境id']
system_module_value = test_data['信增系統模塊id']
print('project_key:%s,summary:%s,description:%s,issuetype:%s,assignee:%s,parent:%s,test_env:%s,sys_module:%s' % (
project_key, summary, description, issuetype, assignee, parent, test_environment_value, system_module_value))
try:
new_issue = jira_info(jira_server, jira_username, jira_password).create_issue(
project={'key': str(project_key)},
summary=str(summary),
description=str(description),
issuetype={'id': int(issuetype)},
assignee={'name': str(assignee)},
parent={'key': str(parent)},
customfield_10265={"id": str(test_environment_value)},
customfield_10268={"id": str(system_module_value)},
)
print(f"新建的任務已創建,其ID為:{new_issue.key}")
except Exception as e:
print('異常: %s' % e)
finally:
print("Operation completed. Check the error log if any issues.")
總結
以上是生活随笔為你收集整理的python jira 读取表数据批量新建子任务的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何设计一个高并发系统?
- 下一篇: 【Java 进阶篇】使用 Stream