[TIP] Functions for tests instead of classes

Michael Foord fuzzyman at voidspace.org.uk
Wed Mar 3 11:15:28 PST 2010


Hello all,

Some of you are *really* keen to use functions instead of classes for 
testing.

Attached is an example of one way of doing that using unittest2 and the 
load_tests protocol.

To use it in your own test modules simply import make_load_tests and add 
the following to your test modules:

load_tests = make_load_tests(__name__)

At the moment there are no assert functions (I may expand simpletest to 
include these at some point) so you can use assert statements, with the 
cost of the useful failure messages unless you construct them yourself.

Once Holger and Benjamin have worked on their ast transformation code it 
should be possible to add this to simpletest for better failure messages 
with plain asserts.

Not that I'll ever use this myself of course...

All the best,

Michael Foord

-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf 
of your employer, to release me from all obligations and waivers arising 
from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, 
shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, 
non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have 
entered into with your employer, its partners, licensors, agents and 
assigns, in perpetuity, without prejudice to my ongoing rights and 
privileges. You further represent that you have the authority to release 
me from any BOGUS AGREEMENTS on behalf of your employer.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: simpletest.py
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20100303/38900900/attachment.txt>


More information about the testing-in-python mailing list