Verifying assertion failures
> No there isn't, unless you specify it. Why would it
> be nice (give an example from real code)?
I'm working on a test framework. I'd like to use assertions
as one of the ways to know that something has failed in a
test. It'd be nice to put in the logs *what* exactly went
wrong, so that the guy checking the problems may solve the
case as fast as possible. I don't think this is abusive
use of assertions, since that's exactly what they exist
for... checking that something that *should* be in some
way is really that way, and failing otherwise. Logging the
assertion that has failed is useful for me and probably
will be for others as well.
> Suppose it is implemented. What is the content of that
> exception when done in the context of
> a = 0
> b = 1
> assert a == b == (a == math.sqrt(a))
> I can think of two possibilities
> The first is to use the string
> "a == b == (a == math.sqrt(a))"
> that is, to use the exact text representation of the
> exception. Since assertions should not occur in working
> code, this would be used for debugging. Since you have
> the source code when debugging, this information comes
> up in the stack trace, or you can use the same methods
> to write a function to get that code.
Yes that's the implementation I was thinking of. Notice that,
specifically in my case, the guy doing the debuggings will
also look for the bug in the environment the framework is
> The second is to somehow insert actual values for the
> different part of the assertion, as in using the text
> 0 == 1 == (0 == math.sqrt(0))
Hummm.. no, that's not what I had in mind. This wouldn't
help much. Think about something like:
assert a == b
assert c == d
Then... Oops! "assert 0 == 1" has failed!! :-)
And, as you mentioned, there's other reasons of why to not
Thanks for your thoughts Andrew!
[ 2AAC 7928 0FBF 0299 5EB5 60E2 2253 B29A 6664 3A0C ]