On Tue, Apr 28, 2009 at 12:54 +0200, Laura Creighton wrote:
> In a message of Tue, 28 Apr 2009 12:14:54 +0200, holger krekel writes:
> >i agree, the error message is slightly mysterious. what about this:
> >
> > def test_inconsistent():
> > def f(l=[1,0]):
> > return l.pop()
> >> assert f()
> >E AssertionError: (assert failed but re-evaluating the
> >assert expression for printing intermediate values lead to a
> >True value. advise: avoid side-effects in assert expressions
> >or use --nomagic)
> >
> >It's a bit longish but i doubt people encountering the problem
> >would know where to lookup things in the documentation.
> >Any other suggestion for the error message?
> >
> >cheers,
> >
> >holger
>
> I think that if you are going to be that long, then you might as well
> be a bit longer. I also think that the word you were looking for was
> 'advice', which rhymes with mice, and is a noun, and not 'advise'
> which rhymes with 'surprise' and is a verb, which means to give
> somebody advice. I like 'suggest' better, but maybe that is just me.
ok :)
> When I've run into this before it is in the context of doing TDD with
> children. They don't know what a side effect is, and I don't think
> that your error message explains that there is a real problem with the
> way that they wrote the assert in the first place. At any rate, the
> puzzling thing around here was that it passed in the second case,
> not that it failed the first time around, but it left students with
> the idea that maybe their code was correct, when it wasn't.
ok, that means to me to try to avoid the term "side-effect".
> I also think that it is more natural to talk about asserts failing and
> then passing, or being false and then true, rather than failing and
> then becoming true.
>
> So here's my attempt at an error message:
>
> E: AssertionError: Evaluating the assert has undesirable side-effects.
> The assert fails when the test is first run, but when subsequently
> re-evaluated for printing intermediate values, it passes. Suggest:
> rewriting the assert expression in a way that avoids side-effects, or
> use --nomagic)
taking your valid points into account, i'd
i'd like to go with something like this (re-posting the func example):
def test_inconsistent():
def f(l=[1,0]):
return l.pop()
> assert f()
E: AssertionError: (assertion failed, but when it was re-run for
printing intermediate values, it did not fail. Suggestions:
compute assert expression before the assert or use --nomagic)
fine to you?
thanks & cheers,
holger
_______________________________________________
py-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/py-dev