Michael Foord committed 361b9a9

Adding pickle test (from Python issue 10326) and updating README

Comments (0)

Files changed (2)

 ``warnings.catch_warnings()`` which is new in Python 2.6 (and is used as a
 context manager which would be a pain to make work with Python 2.4).
-The underlying dictionary storing the type equality functions on TestCase is a
-custom object rather than a real dictionary. This allows TestCase instances to
-be deep-copyable on Python versions prior to 2.7.
 ``TestCase.longMessage`` defaults to True because it is better. It defaults to
 False in Python 2.7 for backwards compatibility reasons.
 discovery with the default parameters from the directory containing, so
 it is perhaps most useful as an example (see unittest2/
+In unittest2 TextTestResult.stopTestRun is responsible for calling printErrors.
+This is desirable behaviour but in Python 3.1 TestResult.stopTestRun was
+documented as being empty and subclasses shouldn't need to call it. This would
+make the change backwards incompatible and needs thinking about.
 * Fix Python issue 9926. TestSuite subclasses that override __call__ are called
 2010/07/12 - 0.5.1


 import difflib
+import pickle
 import pprint
 import re
                           self.assertDictContainsSubset, {'a': 1, 'c': 1},
                           {'a': 1}, '.*Missing:.*Mismatched values:.*')
                           self.assertDictContainsSubset, {1: "one"}, {})
         self.assertItemsEqual([{'a': 1}, {'b': 2}], [{'b': 2}, {'a': 1}])
         self.assertRaises(self.failureException, self.assertItemsEqual,
                           [[1]], [[2]])
         # Test unsortable objects
         self.assertItemsEqual([2j, None], [None, 2j])
         self.assertRaises(self.failureException, self.assertItemsEqual,
+    def testPickle(self):
+        # Issue 10326
+        # Can't use TestCase classes defined in Test class as
+        # pickle does not work with inner classes
+        test = unittest2.TestCase('run')
+        for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
+            # blew up prior to fix
+            pickled_test = pickle.dumps(test, protocol=protocol)
+            unpickled_test = pickle.loads(pickled_test)
+            self.assertEqual(test, unpickled_test)
+            # exercise the TestCase instance in a way that will invoke
+            # the type equality lookup mechanism
+            unpickled_test.assertEqual(set(), set())
 if __name__ == "__main__":
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.