Index: Lib/unittest/test/test_case.py =================================================================== --- Lib/unittest/test/test_case.py (revision 86275) +++ Lib/unittest/test/test_case.py (working copy) @@ -282,6 +282,51 @@ Foo('test').run() + # TestCase.run() reports SkipTest when raised from + # tearDown() + def test_run_skip_in_teardown_when_successful(self): + # issue 9857 + class Foo(unittest.TestCase): + def testNothing(self): + pass + def tearDown(self): + raise unittest.SkipTest + test = Foo('testNothing') + result = unittest.TestResult() + test.run(result) + self.assertTrue(result.wasSuccessful()) + self.assertEqual(1, len(result.skipped)) + + # Test with an 'Error' result should not also report being + # skipped when SkipTest is raised from tearDown + def test_run_skip_in_teardown_when_error(self): + # issue 9857 + class Foo(unittest.TestCase): + def testNothing(self): + raise ValueError + def tearDown(self): + raise unittest.SkipTest + test = Foo('testNothing') + result = unittest.TestResult() + test.run(result) + self.assertFalse(result.wasSuccessful()) + self.assertEqual([], result.skipped) + + # Test with a 'Failure' result should not also report being + # skipped when SkipTest is raised from tearDown + def test_run_skip_in_teardown_when_failure(self): + # issue 9857 + class Foo(unittest.TestCase): + def testNothing(self): + self.assertTrue(False) + def tearDown(self): + raise unittest.SkipTest + test = Foo('testNothing') + result = unittest.TestResult() + test.run(result) + self.assertFalse(result.wasSuccessful()) + self.assertEqual([], result.skipped) + # "This class attribute gives the exception raised by the test() method. # If a test framework needs to use a specialized exception, possibly to # carry additional information, it must subclass this exception in Index: Lib/unittest/case.py =================================================================== --- Lib/unittest/case.py (revision 86275) +++ Lib/unittest/case.py (working copy) @@ -343,6 +343,9 @@ try: self.tearDown() + except SkipTest as e: + if success: + result.addSkip(result, str(e)) except Exception: result.addError(self, sys.exc_info()) success = False