diff options
author | Michael Foord <michael@python.org> | 2011-03-17 17:44:18 (GMT) |
---|---|---|
committer | Michael Foord <michael@python.org> | 2011-03-17 17:44:18 (GMT) |
commit | 42ec7cb1050c5d1bdf5d504903fabe8bb372b5da (patch) | |
tree | 6cb48e730f65fb53688baef5dac66a8bed95538f /Lib/unittest/test | |
parent | b2760a0bc5166f61180e5ed7e25bcf4132c68e62 (diff) | |
download | cpython-42ec7cb1050c5d1bdf5d504903fabe8bb372b5da.zip cpython-42ec7cb1050c5d1bdf5d504903fabe8bb372b5da.tar.gz cpython-42ec7cb1050c5d1bdf5d504903fabe8bb372b5da.tar.bz2 |
Issue #10979. unittest stdout buffering now works with class and module setup and teardown.
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r-- | Lib/unittest/test/test_result.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_result.py b/Lib/unittest/test/test_result.py index 64798a1..1c58e61 100644 --- a/Lib/unittest/test/test_result.py +++ b/Lib/unittest/test/test_result.py @@ -497,5 +497,72 @@ class TestOutputBuffering(unittest.TestCase): self.assertEqual(result._original_stderr.getvalue(), expectedErrMessage) self.assertMultiLineEqual(message, expectedFullMessage) + def testBufferSetupClass(self): + result = unittest.TestResult() + result.buffer = True + + class Foo(unittest.TestCase): + @classmethod + def setUpClass(cls): + 1/0 + def test_foo(self): + pass + suite = unittest.TestSuite([Foo('test_foo')]) + suite(result) + self.assertEqual(len(result.errors), 1) + + def testBufferTearDownClass(self): + result = unittest.TestResult() + result.buffer = True + + class Foo(unittest.TestCase): + @classmethod + def tearDownClass(cls): + 1/0 + def test_foo(self): + pass + suite = unittest.TestSuite([Foo('test_foo')]) + suite(result) + self.assertEqual(len(result.errors), 1) + + def testBufferSetUpModule(self): + result = unittest.TestResult() + result.buffer = True + + class Foo(unittest.TestCase): + def test_foo(self): + pass + class Module(object): + @staticmethod + def setUpModule(): + 1/0 + + Foo.__module__ = 'Module' + sys.modules['Module'] = Module + self.addCleanup(sys.modules.pop, 'Module') + suite = unittest.TestSuite([Foo('test_foo')]) + suite(result) + self.assertEqual(len(result.errors), 1) + + def testBufferTearDownModule(self): + result = unittest.TestResult() + result.buffer = True + + class Foo(unittest.TestCase): + def test_foo(self): + pass + class Module(object): + @staticmethod + def tearDownModule(): + 1/0 + + Foo.__module__ = 'Module' + sys.modules['Module'] = Module + self.addCleanup(sys.modules.pop, 'Module') + suite = unittest.TestSuite([Foo('test_foo')]) + suite(result) + self.assertEqual(len(result.errors), 1) + + if __name__ == '__main__': unittest.main() |