[devtools/testlib] Remove assertions about direct usage of CubicWebTC/AutomaticWebTest
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 25 Mar 2015 14:20:56 +0100
changeset 10837 b71511460a4f
parent 10836 af639c960eae
child 10838 b6cfbcdccc7f
[devtools/testlib] Remove assertions about direct usage of CubicWebTC/AutomaticWebTest The point is to be able to use a test runner other than pytest (e.g. nose2, nosetests or py.test) to run CubicWeb test suite. The issue is that most other test loaders inspects members of all base classes of test case classes to determine test methods and it hits this `config` property (actually executing it), which breaks the assertion. So just return None instead of failing. Closes #7817147.
devtools/testlib.py
--- a/devtools/testlib.py	Fri Nov 06 17:02:09 2015 +0100
+++ b/devtools/testlib.py	Wed Mar 25 14:20:56 2015 +0100
@@ -326,8 +326,11 @@
 
         Configuration is cached on the test class.
         """
+        if cls is CubicWebTC:
+            # Prevent direct use of CubicWebTC directly to avoid database
+            # caching issues
+            return None
         try:
-            assert not cls is CubicWebTC, "Don't use CubicWebTC directly to prevent database caching issue"
             return cls.__dict__['_config']
         except KeyError:
             home = abspath(join(dirname(sys.modules[cls.__module__].__file__), cls.appid))
@@ -1256,7 +1259,10 @@
     tags = AutoPopulateTest.tags | Tags('web', 'generated')
 
     def setUp(self):
-        assert not self.__class__ is AutomaticWebTest, 'Please subclass AutomaticWebTest to prevent database caching issue'
+        if self.__class__ is AutomaticWebTest:
+            # Prevent direct use of AutomaticWebTest to avoid database caching
+            # issues.
+            return
         super(AutomaticWebTest, self).setUp()
 
         # access to self.app for proper initialization of the authentication