如何使用Python REST API从VSTS(Azure DevOps)中的查询中提取工作项?

问题描述 投票:0回答:1

我正在使用Azure DevOps的官方Python REST API:https://github.com/Microsoft/azure-devops-python-api

感谢样本,我已经能够从ids中检索有关测试用例的信息。

如何从查询(WIQL)中做到这一点?

这是我到目前为止的代码(使用修改过的标记和链接):

from vsts.vss_connection import VssConnection
from msrest.authentication import BasicAuthentication


token = "hcykwckuhe6vbnigsjs7r3ai2jefsdlkfjslkfj5mxizbtfu6k53j4ia"
team_instance = "https://tfstest.toto.com:8443/tfs/Development/"

credentials = BasicAuthentication("", token)
connection = VssConnection(base_url=team_instance, creds=credentials)


def print_work_items(work_items):
    for work_item in work_items:
        print(
            "{0} {1}: {2}".format(
                work_item.fields["System.WorkItemType"],
                work_item.id,
                work_item.fields["System.Title"],
            )
        )


WIT_CLIENT = (
    "vsts.work_item_tracking.v4_1.work_item_tracking_client.WorkItemTrackingClient"
)
wit_client = connection.get_client(WIT_CLIENT)


def get_TC_by_id(desired_ids):
    work_items = wit_client.get_work_items(ids=desired_ids, error_policy="omit")
    print_work_items(work_items)


def get_TC_from_query(query):
    # THIS FUNCTION IS NOT WORKING...
    work_items = wit_client.get_work_items(query=query, error_policy="omit")
    print_work_items(work_items)


get_TC_by_id([1035375])

get_TC_from_query(
    """\
SELECT
        [System.Id],
        [System.WorkItemType],
        [System.Title],
        [System.State],
        [System.AreaPath],
        [System.IterationPath]
FROM workitems
WHERE
        [System.TeamProject] = @project
        AND [System.WorkItemType] = 'Test Case'
ORDER BY [System.ChangedDate] DESC
"""
)

这是我得到的错误

  File "test_TFS.py", line 35, in get_TC_from_query
    work_items = wit_client.get_work_items(query=query, error_policy="omit")
TypeError: get_work_items() got an unexpected keyword argument 'query'

如何从查询中检索测试用例?

特别是,我不理解“客户”的价值,如"vsts.work_item_tracking.v4_1.work_item_tracking_client.WorkItemTrackingClient"

谢谢你们!

python rest tfs azure-devops azure-devops-rest-api
1个回答
1
投票

在VithS示例的Github存储库上发布消息(即问题导致pull request)之后,我得到了一个提示来解决我的问题。

解决方案是使用:

  • 带有Wiql类的wiql查询对象
  • query_by_wiql功能
  • 将查询结果(带有WorkItem id的引用)转换为带有qazxsw poi函数的工作项(或qazxsw poi一次性处理多个WorkItem)

这是我解决问题的方法:

get_work_item
© www.soinside.com 2019 - 2024. All rights reserved.