I have problem using dict in python, I just end up with empty dictionary.
looks like I erase the data each itartion
this code suppose to generate a tests that include tests for each site.
thanks in advance
tests={}
for t in Test.objects.all():
for s in Site.objects.all():
site={}
for sv in s.siteversions.all():
siteversion=sv.version
results=sv.results.filter(idTest=t)
result=""
if(results):
result=results[0].result_test()
site.update({sv.version:result})
tests.update({t.name:site.copy()})
print tests
{u'load stuff': {u'X2': 'Success', u'X1': ''}}
{u'load stuff': {u'XP': 'Error'}}
{u'load stuff': {}}
{u'load stuff': {}, u'unload': {u'X2': 'Fail', u'X1': 'Error'}}
{u'load stuff': {}, u'unload': {u'XP': 'Success'}}
{u'load stuff': {}, u'unload': {}}
x2 and xp are versions
tests.update({t.name:site.copy()})is executed for each site but with the same key: testname and somtimes you have sites witout test -> end up with empty dictionary.to fix this you need a strcture like the following:
something like this: