如何使用Python REST API从VSTS(Azure DevOps)检索测试结果?
文档(截至今天)非常简单,甚至API示例专用存储库中的示例也很轻松(https://github.com/Microsoft/azure-devops-python-samples) .
由于某些原因,测试结果不被视为WorkItems,因此常规的WIQL查询将不起作用 .
此外,查询给定区域路径的结果会很棒 .
谢谢
如何使用Python REST API从VSTS(Azure DevOps)检索测试结果?
文档(截至今天)非常简单,甚至API示例专用存储库中的示例也很轻松(https://github.com/Microsoft/azure-devops-python-samples) .
由于某些原因,测试结果不被视为WorkItems,因此常规的WIQL查询将不起作用 .
此外,查询给定区域路径的结果会很棒 .
谢谢
1 回答
首先,您需要使用与测试结果匹配的客户端字符串来获取正确的连接客户端 .
从vsts.vss_connection导入来自msrest.authentication的VssConnection导入BasicAuthentication
然后,您可以查看以下所有可用功能:
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
和max_last_updated_date
之间有7天的限制范围要从给定区域路径中的测试计划中检索所有结果,我使用了以下代码:
请注意,测试结果包含以下属性:
duration_in_ms
build
outcome
(String)associated_bugs
run_by
(身份)test_case
(TestCase)test_case_title
(字符串)area
(AreaPath)Test_run
,对应于测试运行test_suite
test_plan
completed_date
(Python日期时间对象)started_date
(Python日期时间对象)configuration
希望它可以帮助其他人节省我花在探索这个API上的小时数 .
干杯