azure-devops-python-samples icon indicating copy to clipboard operation
azure-devops-python-samples copied to clipboard

Get test result for a specific test case

Open pbissert opened this issue 6 years ago • 6 comments

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?

pbissert avatar Feb 06 '19 16:02 pbissert

There's an endpoint for it, so there will be a Python API for it as well.

vtbassmatt avatar Feb 06 '19 18:02 vtbassmatt

You're right. That didn't exist in the API v4.1, so now we wait.

pbissert avatar Feb 06 '19 18:02 pbissert

@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 avatar Feb 06 '19 18:02 tedchamb

@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?

pbissert avatar Feb 06 '19 19:02 pbissert

@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.

  1. 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'?

  2. 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.

BOB-PHL avatar Dec 30 '20 23:12 BOB-PHL

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.

vtbassmatt avatar Jan 04 '21 15:01 vtbassmatt