diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-10 20:49:30 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-10 20:49:30 (GMT) |
commit | 0734c632d583578a52e83cd88063a95455436b83 (patch) | |
tree | 045e042e985707c676609e019c3ee2359e6c5d8c /Lib | |
parent | 610326d48ac112524ede8182f695fdf8115a0c92 (diff) | |
download | cpython-0734c632d583578a52e83cd88063a95455436b83.zip cpython-0734c632d583578a52e83cd88063a95455436b83.tar.gz cpython-0734c632d583578a52e83cd88063a95455436b83.tar.bz2 |
Issue #7197: Allow unittest.TextTestRunner objects to be pickled and
unpickled. This fixes crashes under Windows when trying to run
test_multiprocessing in verbose mode.
Additionally, Test_TextTestRunner hadn't been enabled in test_unittest.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_unittest.py | 16 | ||||
-rw-r--r-- | Lib/unittest/runner.py | 2 |
2 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py index 726ac85..db51f77 100644 --- a/Lib/test/test_unittest.py +++ b/Lib/test/test_unittest.py @@ -17,6 +17,7 @@ from unittest import TestCase, TestProgram import types from copy import deepcopy from cStringIO import StringIO +import pickle ### Support code ################################################################ @@ -3477,6 +3478,19 @@ class Test_TextTestRunner(TestCase): expected = ['startTestRun', 'stopTestRun'] self.assertEqual(events, expected) + def test_pickle_unpickle(self): + # Issue #7197: a TextTestRunner should be (un)pickleable. This is + # required by test_multiprocessing under Windows (in verbose mode). + import StringIO + # cStringIO objects are not pickleable, but StringIO objects are. + stream = StringIO.StringIO("foo") + runner = unittest.TextTestRunner(stream) + for protocol in range(pickle.HIGHEST_PROTOCOL + 1): + s = pickle.dumps(runner, protocol=protocol) + obj = pickle.loads(s) + # StringIO objects never compare equal, a cheap test instead. + self.assertEqual(obj.stream.getvalue(), stream.getvalue()) + class TestDiscovery(TestCase): @@ -3766,7 +3780,7 @@ def test_main(): test_support.run_unittest(Test_TestCase, Test_TestLoader, Test_TestSuite, Test_TestResult, Test_FunctionTestCase, Test_TestSkipping, Test_Assertions, TestLongMessage, - Test_TestProgram, TestCleanUp, TestDiscovery) + Test_TestProgram, TestCleanUp, TestDiscovery, Test_TextTestRunner) if __name__ == "__main__": test_main() diff --git a/Lib/unittest/runner.py b/Lib/unittest/runner.py index 67839f5..99819df 100644 --- a/Lib/unittest/runner.py +++ b/Lib/unittest/runner.py @@ -12,6 +12,8 @@ class _WritelnDecorator(object): self.stream = stream def __getattr__(self, attr): + if attr == 'stream': + raise AttributeError(attr) return getattr(self.stream,attr) def writeln(self, arg=None): |