[TIP] Unittest Changes

Pekka Laukkanen peke at iki.fi
Mon Jul 21 06:46:02 PDT 2008


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

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

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


More information about the testing-in-python mailing list