[issue2241] Additional Flag For Unit-Test Module: There Can Be Only One (Error)

Steve Purcell report at bugs.python.org
Thu Mar 6 09:27:28 CET 2008


Steve Purcell added the comment:

Hi Brian; 

The module is intended for test suites where the unit tests are written 
to be independent of each other, which is the "standard" way to do 
things.  Note, for instance, that there is no convenient support for 
changing the order in which tests run.

When tests are written like that, you can interrupt a bulk test run at 
any point, and you can run a single test to reproduce and then debug a 
failure.

Given your test suite, I can see how this '--one' option is helpful to 
you, but I don't believe it should be made standard.  (I've never seen 
it in any XP-inspired test framework or related IDE UI.)  However, you 
can easily write a custom TestRunner that provides this "fast abort" 
behaviour that you want, and then hook it into unittest as follows:

   unittest.main(testRunner=MyCustomTestRunner())

(BTW, regarding the implementation, it's not ideal to pass the 'onlyOne' 
parameter down and through to the run() method; much better would be to 
initialise a TestResult subclass with the 'onlyOne' option, so that it 
could then abort when 'addError' or 'addFailure' is called.  You can use 
that trick in any custom test runner you might write.)

Best wishes,

-Steve

----------
assignee:  -> purcell
resolution:  -> rejected
status: open -> closed

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2241>
__________________________________


More information about the Python-bugs-list mailing list