Using debug print routine inside assert

Peter Hansen peter at engcorp.com
Tue Nov 4 12:15:17 EST 2003


Richard Brodie wrote:
> 
> On the unittest vs. logging debate: logging can be useful at the level, where
> you couldn't deduce from the code what should be happening. For
> example, if you have to interoperate with third-party, possibly buggy clients.
> "What requests have been rejected as malformed?" is a question unit tests can't
> address. OTOH if you are adding debug code to find how an individual unit
> works, that probably is bad practice.

I agree, logging can be very useful.  In fact, we tend to find that we've
built at least some kind of logging into almost every non-trivial program
we write, to make it more efficient to find just such interface-related
problems as you describe above.  There are certainly times when a user or
external program will do something unexpected, and if you have a record
of the situation that caused it, you've got a big head start on finding
the problem.  (Mainly this lets you immediate create a new acceptance test
case, generally reproducing the problem fairly quickly, and then you 
can focus on the debugging process.)

For internal interfaces, this kind of thing is much less useful if you
have tests, and I would agree it's now "probably bad practice".

-Peter




More information about the Python-list mailing list