I'm new to Python and I'm attempted this task: I'm trying to generate an XML structure based upon tempest test results which already exist in a dictionary (validation_dict). I'm including only test results that do not comply with a pre-existing baseline.
The structure I need my results to take is the one used by Xunit/nose - found here: Xunit: output test results in xunit format
I'm trying to build out my dictionary structure to resemble something like this:
test_results =
{"suite1": {"test1": "test1 result","test2": "test2 result"},
"suite2": {"test3": "test3 result","test4": "test4 result"}
}
This is so it will eventually scale like so (in accordance with the linked Xunit format above):
<testsuite name="suite1">
<testcase name="test1">
<error message="test1 result">
</testcase>
<testcase name="test2">
<error message="test2 result">
</testcase>
</testsuite>
<testsuite name="suite2">
<testcase name="test3">
<error message="test3 result">
</testcase>
<testcase name="test4">
<error message="test4 result">
</testcase>
</testsuite>
Based upon the fact that validation_dict contains all results & I'm trying to build out my dictionary structure based on only those tests which are not compliant with baseline results:
To achieve the above structure, it appears to me that I must to do the following:
A new dictionary (test_results) to store all tests which are non-complaint with baseline If testsuites (suite_name) do not currently exist there, new dictionaries are generate based upon the name of the test suite. Failed tests within the suite are added to each testsuite Tests that did not pass are added to the dictionary
Here's is my approach so far:
for test_result in validation_dict:
is_valid = True
for i in validation_dict:
if validation_dict[i].outcome != 'pass':
test_results = {}
suite = {}
str = validation_dict[i].test_id
str.split(" : ");
suite_name,test_name = str.split(" : ")
# check if suite_name is already in test_results
if suite_name not in test_results.values():
# create new dict based upon testsuite name?
validation_dict[i].suite_name = {}
# if it's not then add a new dict to test_results
validation_dict[i].suite_name[test_name] = validation_dict[i].outcome
I am unable to tell if I am doing this correctly, as I am unable to check the dictionary names to see if they are being named individually based upon each testsuite (suite_name). Maybe I am approaching this problem the wrong way.
No comments:
Post a Comment