[Python-Dev] light-weight testing

Nick Coghlan ncoghlan at gmail.com
Thu Jul 17 12:34:34 CEST 2008


Antoine Pitrou wrote:
> (especially when you come to have setup/teardown functions shared by several 
> tests).

These days, I tend to just write a context manager for common 
setup/teardown code rather than using the setUp/tearDown hooks (at least 
for Python's own test suite, where I have the luxury of assuming 2.5+ as 
the Python version).

Where I find unittest.TestCase quite convenient is when I want to run 
the same set of tests with a few different settings - for those, putting 
the settings into class attributes and then inheriting from the basic 
test case and using different values is very convenient. This trick is 
particularly useful for testing that a class supports inheritance properly.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list