[Twisted-Python] Re: [Twisted-commits] r15100 - So I really do want this stuff

James Y Knight foom at fuhm.net
Sun Nov 13 00:22:20 EST 2005


On Nov 12, 2005, at 9:48 PM, Jonathan Lange wrote:
> Also, I should point out that implementing setUpClass using resources
> will (probably -- I haven't benchmarked) make tests run faster.
>
> Say you have a base:
> [snipped]

How about let's say I have a base:
class DBTestConnector:
     def setUpClass(self):
         if not self.can_connect():
             raise unittest.SkipTest, '%s: Cannot access db' %  
self.TEST_PREFIX

     def can_connect(self):
         raise NotImplementedError()

class SQLiteConnector(DBTestConnector):
     def can_connect(self):
         try: import sqlite
         except: return False
         return True
     def testPool(self):
         [...]

class PyPgSQLADBAPITestCase(DBTestConnector):
   [similar...]

Then, with resources, the run order will be:
   DBTestConnector.setUpClass. DEATH.

As opposed to
   SQLiteConnector.setUpClass
   SQLiteConnector. testPool
   PyPgSQLADBAPITestCase.setUpClass
   PyPgSQLADBAPITestCase. testPool

 From looking at twisted code, setUpClass is hardly ever shared via  
inheritance, and in the few places it is, none of them will be helped:
1) OldCredTestCase - calls warnings.filterWarnings, fast, also should  
be using suppress
2) SignalMixin, shouldn't exist
3) TLSTestCase, calls log.ignoreErrors, fast
4) DBTestConnector, uses attributes of derived classes, will break
5) CFTPClientTestBase, might actually be useful to only call once,  
except that all subclasses override setUpClass anyways.

James




More information about the Twisted-Python mailing list