[TIP] unittest issues and development
fuzzyman at voidspace.org.uk
Wed Feb 10 16:24:33 PST 2010
On 11/02/2010 00:20, Fernando Perez wrote:
>>> as well as top-level names for the various
>>> assertions? Nose.tools does that in a very simple but useful manner
>>> that makes lightweight (non-class-based) tests really nice to write:
>>> def test_foo():
>>> nose.tools.assert_equals(bar, baz, 'nice message)
>> I've never seen the advantage of this over self.assertEquals (ignoring the
>> PEP 8 issue...). :-)
> Ah, they matter if you aren't writing a class: there is no 'self' in
> the function above. One very nice thing about such tests in the
> contexts I work in (scientists who don't necessarily care or want to
> know about objects) is that the above is a valid test that states
> precisely the desired goal with pretty much zero boilerplate.
I still don't see the following two lines as 'boilerplate'... :-)
> If I have to tell scientists that before writing a test they have to
> subclass some special contraption from unittest, and know about self,
> etc, I'd have to postpone testing until classes have been somewhat
> introduced. But the above approach lets me put tests in pretty much
> from day 1, which is good.
That I can understand. I don't think there is really much of a solution
(except perhaps the solutions you already have...) as unittest is pretty
'object-oriented' in its approach.
All the best,
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.
More information about the testing-in-python