2

我正在尝试使用 pyral python 包创建 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)

得到以下错误 -

Rally Defect Opened - DE1234
ERROR: addCollectionItems() takes exactly 3 arguments (4 given) 

请在此处提供帮助,了解如何为缺陷添加标签。提前致谢。

4

1 回答 1

0

您收到此错误是因为该方法的签名如下:

def addCollectionItems(self, target, items)

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

tag_req = rally.get('Tag', fetch=True, query='Name = "TAG NAME"')
tag = tag_req.next()
adds = rally.addCollectionItems(defect, [tag])

或者您可以在创建缺陷时直接使用,无需任何额外的 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)
于 2018-04-13T23:25:40.800 回答