title: How do I create dictionaries from a loop for structuring with XML in Python?
body: <p>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.</p>
  
  <p>The structure I need my results to take is the one used by Xunit/nose - found here: Xunit: output test results in xunit format</p>
  
  <p>I'm trying to build out my dictionary structure to resemble something like this:</p>
  
  <pre><code>test_results = 
      {"suite1": {"test1": "test1 result","test2": "test2 result"},
      "suite2": {"test3": "test3 result","test4": "test4 result"}
  }
  </code></pre>
  
  <p>This is so it will eventually scale like so (in accordance with the linked Xunit format above):</p>
  
  <pre><code>&lt;testsuite name="suite1"&gt;  
      &lt;testcase name="test1"&gt;    
          &lt;error message="test1 result"&gt;  
      &lt;/testcase&gt;  
      &lt;testcase name="test2"&gt;    
          &lt;error message="test2 result"&gt;  
      &lt;/testcase&gt;
  &lt;/testsuite&gt;
  &lt;testsuite name="suite2"&gt;  
      &lt;testcase name="test3"&gt;    
          &lt;error message="test3 result"&gt;  
      &lt;/testcase&gt;  
      &lt;testcase name="test4"&gt;    
          &lt;error message="test4 result"&gt;  
      &lt;/testcase&gt;
  &lt;/testsuite&gt;
  </code></pre>
  
  <p>Based  upon the fact that validation_dict contains all results &amp; I'm  trying to build out my dictionary structure based on only those tests  which are not compliant with baseline results:</p>
  
  <p>To achieve the above structure, it appears to me that I must to do the following:</p>
  
  <p>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</p>
  
  <p>Here's is my approach so far:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>