使用pythonpy将标签添加到拉力缺陷

2024-10-01 00:31:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用pyralpython包创建Rally缺陷。需要添加标记“#TestTag2”。 有没有办法在创建缺陷时添加标签? 我试图在缺陷创建后添加标签。但是有以下错误-

info = {"Workspace": "/workspace/123",
        "Project": "/project/123",
        "Name": "Test Defect",
        "Description": "Test Defect details",
        "Owner": "/user/123",
        "ScheduleState": "Defined",
        }

try:
    defect = rally.create('Defect', info )
    print ("Rally Defect Opened - {0} \n").format(defect.FormattedID)
    adds = rally.addCollectionItems(defect, 'Tag',"#TestTag")
    rally.addCollectionItems(defect,)
    print(adds)
except Exception, details:
    sys.stderr.write('ERROR: %s \n' % details)
    sys.exit(1)

正在获取以下错误-

^{pr2}$

请帮助这里,如何添加一个标签到缺陷。提前谢谢。在


Tags: 标记testinfo错误sys标签detailsprint
1条回答
网友
1楼 · 发布于 2024-10-01 00:31:05

出现此错误是因为方法的签名如下:

def addCollectionItems(self, target, items)

您需要调整代码以传递标记列表:

^{pr2}$

或者,您可以在缺陷创建期间直接使用,而无需任何其他API调用:

from pyral import Rally

SERVER = 'SERVER URL'
USER = 'USER'
PASSWORD = 'PASSWORD'
WORKSPACE = 'WORKSPACE'
TAG = 'TAG NAME'
OWNER_EMAIL = 'bla@bla.com'

rally = Rally(SERVER, USER, PASSWORD, workspace=WORKSPACE)

target_project = rally.getProject()

user_req = rally.get('User', fetch=True, query='EmailAddress = "%s"' % (OWNER_EMAIL))
user = user_req.next()

tag_req = rally.get('Tag', fetch=True, query='Name = "%s"' % (TAG))
tag = tag_req.next()

defect_info ={"Project": target_project.ref,
        "Name": "Test Defect",
        "Description": "Test Defect details",
        "ScheduleState": "Defined",
        "Owner": user.ref,
        "TAGS": [tag],
        }

try:
    defect = rally.create('Defect', defect_info )
    print ("Rally Defect Opened - {0} \n").format(defect.FormattedID)
except Exception, details:
    sys.stderr.write('ERROR: %s \n' % details)

相关问题 更多 >