summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_runner/test_parallel.py17
-rw-r--r--tests/test_utils/test_testcase.py10
2 files changed, 26 insertions, 1 deletions
diff --git a/tests/test_runner/test_parallel.py b/tests/test_runner/test_parallel.py
index e83f53bf4e..8f7bfd5cf8 100644
--- a/tests/test_runner/test_parallel.py
+++ b/tests/test_runner/test_parallel.py
@@ -51,6 +51,13 @@ class SampleFailingSubtest(SimpleTestCase):
with self.subTest(index=i):
self.assertEqual(i, 1)
+ # This method name doesn't begin with "test" to prevent test discovery
+ # from seeing it.
+ def pickle_error_test(self):
+ with self.subTest("TypeError: cannot pickle memoryview object"):
+ self.x = memoryview(b"")
+ self.fail("expected failure")
+
class RemoteTestResultTest(SimpleTestCase):
def _test_error_exc_info(self):
@@ -106,6 +113,16 @@ class RemoteTestResultTest(SimpleTestCase):
with self.assertRaisesMessage(TypeError, msg):
result._confirm_picklable(not_unpicklable_error)
+ def test_unpicklable_subtest(self):
+ result = RemoteTestResult()
+ subtest_test = SampleFailingSubtest(methodName="pickle_error_test")
+ subtest_test.run(result=result)
+
+ events = result.events
+ subtest_event = events[1]
+ assertion_error = subtest_event[3]
+ self.assertEqual(str(assertion_error[1]), "expected failure")
+
@unittest.skipUnless(tblib is not None, "requires tblib to be installed")
def test_add_failing_subtests(self):
"""
diff --git a/tests/test_utils/test_testcase.py b/tests/test_utils/test_testcase.py
index eb6ca80036..0f41f29a23 100644
--- a/tests/test_utils/test_testcase.py
+++ b/tests/test_utils/test_testcase.py
@@ -1,12 +1,20 @@
+import pickle
from functools import wraps
from django.db import IntegrityError, connections, transaction
from django.test import TestCase, skipUnlessDBFeature
-from django.test.testcases import DatabaseOperationForbidden, TestData
+from django.test.testcases import DatabaseOperationForbidden, SimpleTestCase, TestData
from .models import Car, Person, PossessedCar
+class TestSimpleTestCase(SimpleTestCase):
+ def test_is_picklable_with_non_picklable_properties(self):
+ """ParallelTestSuite requires that all TestCases are picklable."""
+ self.non_picklable = lambda: 0
+ self.assertEqual(self, pickle.loads(pickle.dumps(self)))
+
+
class TestTestCase(TestCase):
@skipUnlessDBFeature("can_defer_constraint_checks")
@skipUnlessDBFeature("supports_foreign_keys")