[TIP] Unittest Changes

Michael Foord fuzzyman at voidspace.org.uk
Tue Jul 22 01:35:57 PDT 2008


Pekka Laukkanen wrote:
> 2008/7/22 Michael Foord <fuzzyman at voidspace.org.uk>:
>   
>> Pekka Laukkanen wrote:
>>     
>>> 2008/7/21 Michael Foord <fuzzyman at voidspace.org.uk>:
>>>
>>>       
>>>> Pekka Laukkanen wrote:
>>>>
>>>>         
>>>>> 1) Having assertions available as static methods in a separate module.
>>>>> This would a) make using them with other code easier, and b) make
>>>>> lines shorter since there would be no need for "self.". With JUnit 4
>>>>> and Java 5 you can do """import static org.junit.Assert.assertNull"""
>>>>> and this addition to Python would allow similar """from
>>>>> unittest.asserts import assertNone""".
>>>>>
>>>>>           
>>>> Interesting idea. I wonder if it could be done without altering the
>>>> semantics of the existing API?
>>>>
>>>>         
>>> There could either be a separate 'asserts' module or 'unittest' could
>>> become a higher level module with 'asserts' as a submodule. The latter
>>> change would require changing 'unittest.py' to 'unittest/__init__.py',
>>> but that should not break backwards compatibility. After adding
>>> 'asserts' (sub)module, assert methods in 'unittest.TestCase' could
>>> just call appropriate functions in 'asserts'.
>>>
>>>       
>> Would be worth an experiment to see if it works.
>>     
>
> At least I don't see any reason why it would not. There's some extra
> work in changing filtering of the traceback so that not only lines
> originating inside 'unittest' but also inside 'asserts' are ignore.
> That shouldn't be too hard, though.
>
>   

If you do try it - post the results back to the list.

Michael

-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/
http://www.trypython.org/
http://www.ironpython.info/
http://www.theotherdelia.co.uk/
http://www.resolverhacks.net/




More information about the testing-in-python mailing list