"assert" annoyance

Paul Rubin http
Fri Jun 22 11:05:02 EDT 2007


Ben Finney <bignose+hates-spam at benfinney.id.au> writes:
> > So I have some assert statements in my code to verify the absence of
> > some "impossible" conditions.  They were useful in debugging and of
> > course I left them in place for "real" runs of the program.  Umpteen
> > hours into a run, an assertion failed, and of course since failure
> > was "impossible", I didn't catch the exception so the whole program
> > crashed.
> 
> This is exactly the sort of check which is best done as unit
> tests. The program has no 'assert' cruft in it, and the tests can be
> as comprehensive as needed without having any impact on the actual
> running program.

I don't understand what you're trying to say here.  The code was
tested before I ran it with real data.  The asserts triggered because
there was a real problem, so removing them would not have been the
right thing to do.  On the other hand, the code had already been
tested without discovering the problem.  The problem could not have
been found without running the program for hours, not something one
would normally do in a unit test, and also it involved an unexpected
error from a remote program (a 3GB process had run out of memory).
Unit tests are not a magic wand that discover every problem that a
program could possibly have.



More information about the Python-list mailing list