如何使用pythonrestapi在azuredevops中检索测试结果?

2024-06-25 07:27:06 发布

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

如何使用pythonrestapi从VSTS(azuredevops)检索测试结果?在

文档(到目前为止)非常简单,甚至API示例的专用repo中的示例也很简单(https://github.com/Microsoft/azure-devops-python-samples)。在

由于某些原因,测试结果不被视为工作项,因此常规的WIQL查询将无法工作。在

此外,查询给定区域路径的结果将非常有用。在

谢谢


Tags: 文档httpsgithubcomapi示例repoazure
1条回答
网友
1楼 · 发布于 2024-06-25 07:27:06

首先,您需要使用与测试结果匹配的客户机字符串获得正确的连接客户机。在

从vsts.vss_连接导入VssConnection 从msrest.身份验证导入基本身份验证

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

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

TEST_CLIENT = "vsts.test.v4_1.test_client.TestClient"
test_client = connection.get_client(TEST_CLIENT)

然后,您可以查看:vsts/test/<api_version>/test_client.py"中可用的所有函数

以下函数看起来很有趣:

  • def get_test_results(self, project, run_id, details_to_include=None, skip=None, top=None, outcomes=None)(根据筛选器获取运行的测试结果)
  • def get_test_runs(self, project, build_uri=None, owner=None, tmi_run_id=None, plan_id=None, include_run_details=None, automated=None, skip=None, top=None)
  • def query_test_runs(self, project, min_last_updated_date, max_last_updated_date, state=None, plan_ids=None, is_automated=None, publish_context=None, build_ids=None, build_def_ids=None, branch_name=None, release_ids=None, release_def_ids=None, release_env_ids=None, release_env_def_ids=None, run_title=None, top=None, continuation_token=None)(尽管此函数的范围限制在min_last_updated_date和{}之间7天

为了检索给定区域路径中测试计划的所有结果,我使用了以下代码:

^{pr2}$

请注意,测试结果包括以下属性:

  • duration_in_ms
  • build
  • outcome(字符串)
  • associated_bugs
  • run_by(标识)
  • test_case(测试用例)
  • test_case_title(字符串)
  • area(区域路径)
  • Test_run,对应于测试运行
  • test_suite
  • test_plan
  • completed_date(Python datetime对象)
  • started_date(Python datetime对象)
  • configuration

希望它能帮助其他人节省我花在探索这个API上的时间。在

干杯

相关问题 更多 >