azure-devops-python-samples
azure-devops-python-samples copied to clipboard
Get test result for a specific test case
In .../samples/test.py, you have a function, def get_test_results(context):
This appears to get all of the test results for a given context. Is it possible to get the test result of a single test case?
There's an endpoint for it, so there will be a Python API for it as well.
You're right. That didn't exist in the API v4.1, so now we wait.
@pbissert Is this what you are looking for get_test_result_by_id:
https://github.com/Microsoft/azure-devops-python-api/blob/d16026911f93361becb52d2f1c124d5c3e8a82e7/vsts/vsts/test/v4_1/test_client.py#L1167
The API is there in 4.1, it is just not documented on the site.
@tedchamb Thanks for pointing that out. Let me see if I can get it to work.
Really I'm just trying to get the latest outcome for a given test case. It seems like the path to get there is to loop through all run ids (get_test_runs) loop through the test results for an iterations run id, then check the test case.
desired_test_case = 1234
for run in test_client.get_test_runs('Portfolio'):
for res in test_client.get_test_results('Portfolio', run.id):
if res.test_case == desired_test_case:
return res.outcome
return None
Is there a more efficient way?
@tedchamb @vtbassmatt
Hello, I had a couple of follow-up questions.
With VSTS v4.1 test_client.py referenced above, I'd like to get the test results (passed, failed, blocked, etc.) for the tests in a test suite.
-
With the 'get_test_results' method, the test results are returned given you have the run_id. Is there a way to get the run_id's for a given 'test case'/'test case ID'?
-
And relatedly, the 'get_test_cases' method returns object addresses for 'point_assignments' and for 'test_case'. Is there a way to obtain the object values/contents for 'point_assignments' and for 'test_case'?
Thanks very much, in advance, for any help/guidance.
Hi @BOB-PHL. If there's a REST API in the Test area which does what you want, then it works from Python. Unfortunately I don't know enough about the Test APIs to comment.