[TIP] Functions for tests instead of classes
fuzzyman at voidspace.org.uk
Thu Mar 4 16:27:15 PST 2010
On 05/03/2010 00:19, Ryan Freckleton wrote:
> On Thu, Mar 4, 2010 at 3:33 PM, Michael Foord
> <fuzzyman at voidspace.org.uk <mailto:fuzzyman at voidspace.org.uk>> wrote:
> On 04/03/2010 22:03, Ryan Freckleton wrote:
>> On Wed, Mar 3, 2010 at 12:15 PM, Michael Foord
>> <fuzzyman at voidspace.org.uk <mailto:fuzzyman at voidspace.org.uk>> wrote:
>> 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.
>> Does that mean we're going to get pretty asserts through ast
>> transforms? As in:
> Well, not in unittest itself but in some extension of unittest...
> There is an implementation that could be adapted fairly easily:
> This uses the ast module which is new in Python 2.6, but it could
> be backported to use _ast for Python 2.5. There is also an old
> version called "_assertionold.py" that uses the compiler module
> present in Python 2.4.
> Cool, I'll look at that in detail.
> There is also code in nose that does something similar (stack
> introspection rather than ast transformation I *believe*) in nose.
> If unittest had a good extension API this could just be
> implemented as a unittest extension...
> Thanks for the pointers, once I get some more free cycles I'll try to
> implement a "pretty asserts" module. Hopefully it can end up being one
> of the first unittest2 extensions :)
It will need the extensibility mechanism in place to be generally usable
For simpletest you could wrap it around the functions easily enough -
catching AssertionError and then doing the ast transform and rerun,
raising a 'better' exception on failure. When I say easily enough that
is for some unspecified value of 'easily' of course (the wrapping is
easy it is untangling the ast transform code from py.test that will take
a little bit of work)...
Anyway - I'll be interested in what you come up with.
> All the best,
> --Ryan E. Freckleton
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 HTML attachment was scrubbed...
More information about the testing-in-python