summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Laxalde <denis.laxalde@logilab.fr>2014-06-05 10:06:59 +0200
committerDenis Laxalde <denis.laxalde@logilab.fr>2014-06-05 10:06:59 +0200
commitb0f384ef4bb2d7e5ac419320c73199b0aed65ee7 (patch)
tree7cee5f5ca7f8d7947a93ed6764ecab14bedd7591
parent86dc908ee0df6f8bf9a0bd11d9952dcaba0689e4 (diff)
downloadlogilab-common-b0f384ef4bb2d7e5ac419320c73199b0aed65ee7.tar.gz
[testlib] Handle skip methods as in unittest
Just copied this piece of code from unittest.TestCase.run which: * makes it possible to skip whole TestCase (using class decorator), * handle conditional skip (skipIf). As an aside, with this, setUp() is not executed anymore when a test is skipped. Closes #252838.
-rw-r--r--ChangeLog2
-rw-r--r--testlib.py10
2 files changed, 12 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 0560fef..5406478 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,8 @@ ChangeLog for logilab.common
--
* shellutils: restore py 2.5 compat by removing usage of class decorator
* pytest: drop broken --coverage option
+ * testlib: support for skipping whole test class and conditional skip, don't
+ run setUp for skipped tests
* configuration: load options in config file order (#185648)
2014-03-07 -- 0.62.0
diff --git a/testlib.py b/testlib.py
index 817149c..683c7ac 100644
--- a/testlib.py
+++ b/testlib.py
@@ -579,6 +579,16 @@ class TestCase(unittest.TestCase):
# if result.cvg:
# result.cvg.start()
testMethod = self._get_test_method()
+ if (getattr(self.__class__, "__unittest_skip__", False) or
+ getattr(testMethod, "__unittest_skip__", False)):
+ # If the class or method was skipped.
+ try:
+ skip_why = (getattr(self.__class__, '__unittest_skip_why__', '')
+ or getattr(testMethod, '__unittest_skip_why__', ''))
+ self._addSkip(result, skip_why)
+ finally:
+ result.stopTest(self)
+ return
if runcondition and not runcondition(testMethod):
return # test is skipped
result.startTest(self)