[TIP] Unittest Changes

Michael Foord fuzzyman at voidspace.org.uk
Mon Jul 21 13:51:39 PDT 2008


Pekka Laukkanen wrote:
> Hello,
>
> it's great to hear that unittest will be enhanced! My favorite
> extensions to it would be:
>
> 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?

> 2) Having PEP-8-style aliases for asserts. PEP-8 reminds that
> consistency within a module is most important, but now my test modules
> have inconsistent lines like
> """self.assertEquals(do_something_interesting, expected_value)""".
> Asserts can be also used with non-test code (and above point would
> make that even easier), and then adhering PEP-8 is even more
> important.
>   

Off the table for standard library inclusion, see the BDFL pronouncement 
on Python-Dev.

Michael

>
> We needed these features so badly in Robot Framework [1] that we
> created a utility module implementing them. Its code is available at
> [2]. The code is, of course, trivial but the doc string has some more
> examples etc.
>
> [1] http://robotframework.org
> [2] http://code.google.com/p/robotframework/source/browse/trunk/src/robot/utils/asserts.py
>
>
> Cheers,
>     .peke
>   


-- 
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