Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

Field :results is a required field error


#1

Hi,

I am trying to import results into Test rail using python. I generate my json string like this, where testcase_ids is an array of test case ids. :

    for x in testcase_ids:
        result_details = {"case_id": str(x),"status_id": 1,"version":"1.0","comment":"Test"}
        results.append(result_details)
    json_string = json.dumps([{"results": results}])
    json_results = json.loads(json_string)

This produces a json string

print (json.dumps(json_results , indent=4, sort_keys=True))
{
    "results": [
    {
         "case_id": "76565",
         "comment": "Test",
         "status_id": 1,
         "version": "1.0"
     },
     {
         "case_id": "234673",
         "comment": "Test",
         "status_id": 1,
         "version": "1.0"
      }
   ]
}  

However, when i pass this into ‘add_results_for_cases’
add_results_for_cases(run_id, json_results )
print(“Add results: {0}”.format(result))

I get the error
Add results: {‘error’: ‘Field :results is a required field.’}

Thanks,

John.


#2

Forget it… I’ve just spotted my error. I should dump my json string like this:

json_string = json.dumps({"results": results})

But i was doing this: Note the removal of the square brackets.

json_string = json.dumps([{"results": results}])