[Python-Dev] Proposed unittest changes
Nick Coghlan
ncoghlan at gmail.com
Tue Jul 15 11:40:51 CEST 2008
Michael Foord wrote:
> Raymond Hettinger wrote:
>> From: "Ben Finney" <ben+python at benfinney.id.au>
>>> Right, so I'm putting up a separate PEP just for the renaming. Should
>>> be arriving on this list soon.
>>
>> I would like to work with you or someone else who is interested
>> on an alternative PEP for a separate, simpler test module
>> using the py.test syntax. That is much simpler to learn and use.
>> Instead of self.assertIsNot and whatnot, you write:
>> assert a is not b
>> No need for tons of word-by-word spellings on things we already
>> have syntax for. Almost anyone who has used py.test can attest
>> its syntax is much more natural, easy to learn, easy to both
>> read and write, and is much lighter weight. I think some variant
>> of py.test could be done that is compatable with unittest
>> and the did not have the "magic" present in earlier versions of py.test.
>
> Ah, in my haste I skipped over your comment about "magic", my apologies.
> But in the absence of magic how do you propose to provide a meaningful
> error message from the failure of:
>
> assert a == b
>
> To wrap it in a function like "assert equals(a, b)" seems to gain little
> over unittest.
Aside from the question of providing nice error messages, two questions
that immediately come to mind for me are:
- how do I run my tests with -O or -OO? (since the compiler will throw
all the assert statements away before any Python code gets a chance to
look at them)
- how do I test that code raises an expected exception?
- how do I explicitly fail a test case? (e.g. I'll often do this when I
want to test an operation with a variety of different inputs - I'll test
for all of the inputs of interest, collecting the failures in a list,
then reporting a single error message at the end detailing all of the
cases that failed)
And I've also never had any problem whatsoever debugging unit tests with
print statements - one of the effects of the -v switch is to display
anything which is written to stderr/stdout on the console again.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-Dev
mailing list