[Twisted-Python] Running Twisted tests with testtools

Jonathan Lange jml at mumak.net
Mon Feb 6 08:48:01 MST 2012


Hello,

I'm the nominal maintainer of Trial. I'm also an active maintainer of
testtools[1].

testtools is, roughly speaking, a base TestCase that works across a
bunch of Pythons and has a few nice features[2]. I started to prefer
it over Twisted's TestCase some time ago, and now use it pretty
consistently, even for my Twisted code.

testtools has a way of letting you run tests within the Twisted
reactor, without needing to use a particular base class. For example::

  class MyTests(TestCase):
    run_tests_with = AsynchronousDeferredRunTest

    def test_foo(self):
      ...
      return some_deferred

Or::

  class MyTests(TestCase):
    def test_ordinary_thing(self):
      ...
    @run_test_with(AsynchronousDeferredRunTest)
    def test_twisted_thing(self):
      ...
      return some_deferred

It doesn't behave exactly the way Trial does. Freed from backwards
compatibility constraints, I tightened up the implementation quite a
bit. There are options to make it emulate Trial's behaviour[3].

The documentation says that it's "highly experimental". This is not
strictly true any more, as it has been used in numerous projects and
has been found to be quite robust.

The key source code is at::
  http://bazaar.launchpad.net/~testtools-committers/testtools/trunk/view/head:/testtools/deferredruntest.py
  http://bazaar.launchpad.net/~testtools-committers/testtools/trunk/view/head:/testtools/_spinner.py

And you can get the code from PyPI or Launchpad[4].

testtools has had this feature for some time now. It's past time that
I officially informed the Twisted community about it. That's the main
reason for this email.

In my ideal world, Twisted's TestCase would inherit from testtools's
TestCase and would continue to provide the same API it does today.
This might not be everyone else's ideal though, and the path from here
to there is unclear to me. I welcome your thoughts.

cheers,
jml


[1] http://testtools.rtfd.org ; http://pypi.python.org/pypi/testtools
[2] http://testtools.readthedocs.org/en/latest/overview.html
[3] http://testtools.readthedocs.org/en/latest/for-test-authors.html#twisted-support
[4] bzr branch lp:testtools




More information about the Twisted-Python mailing list