【发布时间】:2014-05-03 10:50:25
【问题描述】:
我有一段代码
assert (len(max_test_scores) != 1), \
"Internal error - migration 0011 - module Programs." \
" Please contact with developers - " + str(len(max_test_scores))
在执行这段代码的过程中,我遇到了一个断言错误:
AssertionError:内部错误 - 迁移 0011 - 模块程序。请与开发者联系 - 1
所以 1 != 1 ?
我一直在搜索、谷歌搜索并思考这是如何发生的,但我不知道。这是带有上下文的代码
def forwards(self, orm):
problems_and_groups = orm.Test.objects \
.values('problem', 'group').distinct()
problems_instances_and_groups = []
for pi in orm['contests.ProblemInstance'].objects.all():
for pg in problems_and_groups:
if pi.problem.pk == pg['problem']:
problems_instances_and_groups \
.append({'problem_instance': pi.pk,
'group': pg['group']})
count = len(problems_instances_and_groups)
num = 0
update_every = max(1, count / 20)
pb = ProgressBar(count)
print "Migrating %d groups" % count
for pig in problems_instances_and_groups:
if num % update_every == 0:
pb.update(num)
num += 1
submissions = orm['contests.Submission'].objects \
.filter(problem_instance = pig['problem_instance']) \
.values('pk')
print submissions
submission_reports = orm['contests.SubmissionReport'].objects \
.filter(submission__in = submissions).values('pk')
print submission_reports
test_reports = orm.TestReport.objects \
.filter(test_group = pig['group'],
submission_report__in = submission_reports)
max_score = None
max_test_scores = frozenset(test_report.test.max_score
for test_report in test_reports)
assert (len(max_test_scores) != 1), \
"Internal error - migration 0011 - module Programs." \
" Please contact with developers - " + str(len(max_test_scores))
max_score = ScoreValue(list(max_test_scores)[0])
GroupReport.filter(test_group=pig['group'],
submission_report__in = submission_reports) \
.update(max_score=max_score)
【问题讨论】:
-
你在哪里证明
len(max_test_scores)不等于1? -
@LukasGraf 在断言消息中。
-
@MatthewTrevor 是的,因为 str(len(max_test_scores)) 等于 1
-
@bdfhjk 这就是你的断言。它失败了。所以
len(max_test_scores)显然是 等于1。但是您告诉我们它不是,因此“Python 在撒谎”。而且您的示例不包含以其他方式显示的必要数据。 -
好吧,我知道问题出在哪里了 :)
标签: python django assertions