[Twisted-Python] twisted.trial and test discovery

Jonathan Lange jml at mumak.net
Wed Sep 19 19:50:50 EDT 2007

On 9/20/07, Drew Smathers <drew.smathers at gmail.com> wrote:
> > I'm not sure I understand. Trial already does test discovery. "trial
> > yourpackage" will find all the test cases in your package.
> Yes, I know.  It will not pick up doctests defined in plain text files
> (mymod.txt - like you see frequently in zope projects) or in doc
> strings from my experiments.  Of course, this is just me being lazy  -
> especially for doctests inside of modules where I can make a trivial
> test_doc module to collect these:
> from myproject import web, auth, i18n
> __doctests__ = [ web, auth, i18n ]

In this case, Trial follows the principle that "explicit is better
than implicit". Rather than treating every random snippet of text as a
potential doctest, it's reasonable that documents have be *declared*
as executable.

If you want to do something a little more automated than assigning
things to __doctest__, Trial lets you hook into the test discovery
system by defining a 'test_suite' method in your module. This allows
you to customize your test discovery for your project.


More information about the Twisted-Python mailing list