Unit testing (was Re: Is this considered black magic?)

Peter Hansen peter at engcorp.com
Sun Nov 11 20:40:25 CET 2001

Laura Creighton wrote:
> I want to do something which is conceptually very simple.  Given a list of
> objects, make everybody call the same method you want to run.  Sort
> of like apply(), but for methods.
>     foreach ('say', [h, e, s])
>     foreach('speak_up', [e])
>     foreach('speak_up', [h, e, s], 'sandwich')
>     foreach('speak_up', [h, e, s], None) #can i pass None?

Peter Hansen replied in an email:

> By the way, what you are writing is on the verge
> of being an automatic testing facility.  Are you trying
> to write something as part of a testing framework?

Laura Creighton replied:
> Absolutely correct.  What else do I need to know?

I'm not sure, but I was wondering whether you knew about
unittest.py (aka PyUnit) and automatic testing frameworks?

I'm no expert (just learning) but you should spend a bit of 
time reading the *brilliant* online book by Mark Pilgrim 
http://diveintopython.org .

The chapter on unit testing, if you can take the time to 
read through it thoroughly and haven't already, provides an 
exceptional introduction to the value of unit testing in Python, 
and how to do it:  http://diveintopython.org/roman_divein.html 

Integrating your foreach() method into that kind of framework
could give you a helpful structure in which to work, rather
than reinventing the wheel.

(Of course there's nothing to indicate you didn't already 
know all this.  Just thought I'd check.  :-)

Peter Hansen, P.Eng.
peter at engcorp.com

More information about the Python-list mailing list