[Python-checkins] r76196 - in python/trunk: Lib/test/test_unittest.py Lib/unittest/runner.py Misc/NEWS

antoine.pitrou python-checkins at python.org
Tue Nov 10 21:49:30 CET 2009


Author: antoine.pitrou
Date: Tue Nov 10 21:49:30 2009
New Revision: 76196
Log:
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.
Modified:
 python/trunk/Lib/test/test_unittest.py
 python/trunk/Lib/unittest/runner.py
 python/trunk/Misc/NEWS
Modified: python/trunk/Lib/test/test_unittest.py
==============================================================================
--- python/trunk/Lib/test/test_unittest.py	(original)
+++ python/trunk/Lib/test/test_unittest.py	Tue Nov 10 21:49:30 2009
@@ -17,6 +17,7 @@
 import types
 from copy import deepcopy
 from cStringIO import StringIO
+import pickle
 
 ### Support code
 ################################################################
@@ -3477,6 +3478,19 @@
 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 @@
 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()
Modified: python/trunk/Lib/unittest/runner.py
==============================================================================
--- python/trunk/Lib/unittest/runner.py	(original)
+++ python/trunk/Lib/unittest/runner.py	Tue Nov 10 21:49:30 2009
@@ -12,6 +12,8 @@
 self.stream = stream
 
 def __getattr__(self, attr):
+ if attr == 'stream':
+ raise AttributeError(attr)
 return getattr(self.stream,attr)
 
 def writeln(self, arg=None):
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Tue Nov 10 21:49:30 2009
@@ -426,6 +426,10 @@
 Library
 -------
 
+- 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.
+
 - Issue #7282: Fix a memory leak when an RLock was used in a thread other
 than those started through `threading.Thread` (for example, using
 `thread.start_new_thread()`.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /