[Twisted-Python] Thoughts about testing

Moof moof at metamoof.net
Wed Oct 26 13:48:32 EDT 2005

Glyph Lefkowitz wrote:

>>1. assert, not self.failUnlessAllThisUglyCamelCaseActuallyKillsMe()
> This is cute - more in the way it deals with printing appropriate
> context than the fact that you actually use 'assert' - but it's a shame
> that they resorted to a language hack rather than a simple function like
> 'test()' or something.  Using 'assert' makes it impossible to test with
> -O or -OO.  I personally don't use those options, but some people do,
> and they should be testable.

I do despise the unittest (and hence trial) camelcaseness. I don't know
enough low level python to be able to answer whether a test() function would
have the same drawback as assert, if -O testing is really an issue.

>>3. Tests execute in predictable order.
> ... and then since there is now global state smeared across your whole
> module, the tests have to run in an exact order because each one sets up
> things for the next, rather than proper setUp/tearDown encapsulation.

There is a use case for this, though. py.test has a -x option that will stop
executing after one test returns an error. This is very much a time saver
when you're running a bunch of lengthy tests on a function where one initial
test failing may inevitably mean that a bunch of more sophisticated tests
involving the same item will fail. If I can predictably say that test_x will
always run before test_advanced_x, then I can try to fix the simple version
before doing a lengthy test on the advanced version.

One thing that I did like out of py.test was the ability to name a test or
test object that you wanted to run and it would do magic pattern matching on
the test's __name__ based on what you typed in. It still printed out
non-matching tests as skipped, but it only ran what you wanted. It allows
you to, again, focus on small functionality within a larger test file.

>>4. setup_module / setup_class / setup_method.  Handy for reusing
>>database connections.
> Technically trial has similar features, but they were broken so horribly
> for so long that it became the common wisdom not to use them.  I have to
> assume this has recently changed?

trial.unittest.setUp was changed to work after 2.0 was released on windows,
as I needed to upgrade to twisted svn to get it working.

Giles Antonio Radford, alias Moof
"Too old to be a chicken and too young to be a dirty old man"
Serving up my ego over at <http://metamoof.net/>

More information about the Twisted-Python mailing list