[Twisted-Python] Re: [Twisted-commits] r15100 - So I really do want this stuff
warner at lothar.com
Sun Nov 13 14:15:56 EST 2005
>>This is a bug, not a feature.
> Why is it a bug?
I've been bitten by this behavior.. basically it means that the TestCase's
__init__ method is not invoked for each test method, so you have to remember
to clear status flags (say, things that are set from a Deferred callback,
like maybe a .oopsSomethingFailed flag) in setUp() rather than just
initialize them in __init__ . The annoying thing is that it (the __init__
approach) works fine when you run the tests one at a time, which I frequently
do as I set up a brand new test. It only breaks when you run multiple tests,
and even then only when the leftover results of one test get interpreted by a
I think part of the "clean all lingering state after every test" philosophy
should include cleaning attributes from the test methods themselves (or just
not re-using those objects).
That said, I still want a place to amortize expensive setup across multiple
tests. The buildbot tests, for example, have about half a dozen tests for
each supported version control system. There is a module-level check that
sees which ones you have installed (arch, baz, cvs, svn, darcs), then sets
some flags which cause certain tests to be run or skipped. I don't want to
re-do these checks for each test method. It may work to re-do them for each
TestCase class (say, the setUpClass for the SVN TestCase class checks to see
if SVN is available), but for code factoring purposes there might be multiple
SVN TestCase classes, and it would be nice to avoid duplicate checks.
Incidentally, these checks are the only remaining use of deferredResult() in
the buildbot test suite, at least when it is run against Twisted-2.0 or
newer, because they were originally run at import time. In the current code,
they are performed by the first setUpClass that gets run, and the results are
stashed in a module-level global to avoid running them again. If I were
confident that all supported (by buildbot) versions of Twisted allowed
setUpClass to return a Deferred, I could get rid of that last
More information about the Twisted-Python