summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Cardona <remi.cardona@logilab.fr>2015-09-10 16:37:35 +0200
committerRémi Cardona <remi.cardona@logilab.fr>2015-09-10 16:37:35 +0200
commit5e6dbf7b5c88aca59cacd3536aac0200c0b26119 (patch)
tree48567fbbc5c75dae620011875e535ee3d55cb6d3
parent8294050e2c7f08951b5edac5248117c2807205ea (diff)
downloadlogilab-common-5e6dbf7b5c88aca59cacd3536aac0200c0b26119.tar.gz
[testlib] Allow skipTest() and fail() in generative tests
Closes #1716420.
-rw-r--r--logilab/common/testlib.py5
-rw-r--r--test/unittest_testlib.py25
2 files changed, 30 insertions, 0 deletions
diff --git a/logilab/common/testlib.py b/logilab/common/testlib.py
index 93e74af..42c6947 100644
--- a/logilab/common/testlib.py
+++ b/logilab/common/testlib.py
@@ -572,6 +572,11 @@ class TestCase(unittest.TestCase):
# result.shouldStop = True
if result.shouldStop: # either on error or on exitfirst + error
break
+ except self.failureException:
+ result.addFailure(self, self.__exc_info())
+ success = False
+ except SkipTest as e:
+ result.addSkip(self, e)
except:
# if an error occurs between two yield
result.addError(self, self.__exc_info())
diff --git a/test/unittest_testlib.py b/test/unittest_testlib.py
index bc60669..02abce8 100644
--- a/test/unittest_testlib.py
+++ b/test/unittest_testlib.py
@@ -344,6 +344,31 @@ class GenerativeTestsTC(TestCase):
self.assertEqual(len(result.skipped), 0)
+ def test_generative_outer_failure(self):
+ class FooTC(TestCase):
+ def test_generative(self):
+ self.fail()
+ yield
+
+ result = self.runner.run(FooTC('test_generative'))
+ self.assertEqual(result.testsRun, 0)
+ self.assertEqual(len(result.failures), 1)
+ self.assertEqual(len(result.errors), 0)
+ self.assertEqual(len(result.skipped), 0)
+
+ def test_generative_outer_skip(self):
+ class FooTC(TestCase):
+ def test_generative(self):
+ self.skipTest('blah')
+ yield
+
+ result = self.runner.run(FooTC('test_generative'))
+ self.assertEqual(result.testsRun, 0)
+ self.assertEqual(len(result.failures), 0)
+ self.assertEqual(len(result.errors), 0)
+ self.assertEqual(len(result.skipped), 1)
+
+
class ExitFirstTC(TestCase):
def setUp(self):
output = StringIO()