[devtools/testlib] Issue a RuntimeError when a generative tests is detected
authorDenis Laxalde <denis.laxalde@logilab.fr>
Thu, 18 Feb 2016 10:23:05 +0100
changeset 11182 66c44d3d97af
parent 11181 2a7fb3422ae1
child 11183 505195fe444d
[devtools/testlib] Issue a RuntimeError when a generative tests is detected Otherwise, generative tests *à la logilab-common* in CubicWebTC test cases would silently not run (at least using logilab.common.pytest runner).
cubicweb/devtools/testlib.py
doc/changes/3.23.rst
--- a/cubicweb/devtools/testlib.py	Thu Feb 18 09:30:58 2016 +0100
+++ b/cubicweb/devtools/testlib.py	Thu Feb 18 10:23:05 2016 +0100
@@ -23,6 +23,7 @@
 from os.path import dirname, join, abspath
 from math import log
 from contextlib import contextmanager
+from inspect import isgeneratorfunction
 from itertools import chain
 
 from six import text_type, string_types
@@ -317,6 +318,14 @@
         self._open_access = set()
         super(CubicWebTC, self).__init__(*args, **kwargs)
 
+    def run(self, *args, **kwds):
+        testMethod = getattr(self, self._testMethodName)
+        if isgeneratorfunction(testMethod):
+            raise RuntimeError(
+                '%s appears to be a generative test. This is not handled '
+                'anymore, use subTest API instead.' % self)
+        return super(CubicWebTC, self).run(*args, **kwds)
+
     # repository connection handling ###########################################
 
     def new_access(self, login):
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/changes/3.23.rst	Thu Feb 18 10:23:05 2016 +0100
@@ -0,0 +1,12 @@
+3.23 (UNRELEASED)
+=================
+
+Backwards-incompatible changes
+------------------------------
+
+* Generative tests *à la logilab-common* are not supported anymore in
+  `CubicWebTC`. It is advised to use the subtests_ API (available on
+  `CubicWebTC` either from the standard library as of Python 3.4 or through
+  unittest2 package otherwise).
+
+.. _subtests: https://docs.python.org/3/library/unittest.html#distinguishing-test-iterations-using-subtests