From 5b618f239ceb884c9380cf42361c7cc69bf1e208 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 25 Mar 2021 10:33:54 +0100 Subject: [PATCH] Fixed RemoteTestResultTest tests without tblib. Follow up to e3bca22e7e572b0274a0814c7869c899d7b544e0. --- tests/test_runner/test_parallel.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/test_runner/test_parallel.py b/tests/test_runner/test_parallel.py index a56d82c7bd..e27579831f 100644 --- a/tests/test_runner/test_parallel.py +++ b/tests/test_runner/test_parallel.py @@ -1,11 +1,12 @@ import pickle +import sys import unittest from django.test import SimpleTestCase from django.test.runner import RemoteTestResult try: - import tblib + import tblib.pickling_support except ImportError: tblib = None @@ -52,6 +53,12 @@ class SampleFailingSubtest(SimpleTestCase): class RemoteTestResultTest(SimpleTestCase): + def _test_error_exc_info(self): + try: + raise ValueError('woops') + except ValueError: + return sys.exc_info() + def test_was_successful_no_events(self): result = RemoteTestResult() self.assertIs(result.wasSuccessful(), True) @@ -63,7 +70,7 @@ class RemoteTestResultTest(SimpleTestCase): def test_was_successful_one_expected_failure(self): result = RemoteTestResult() - result.addExpectedFailure(None, ValueError('woops')) + result.addExpectedFailure(None, self._test_error_exc_info()) self.assertIs(result.wasSuccessful(), True) def test_was_successful_one_skip(self): @@ -71,14 +78,16 @@ class RemoteTestResultTest(SimpleTestCase): result.addSkip(None, 'Skipped') self.assertIs(result.wasSuccessful(), True) + @unittest.skipUnless(tblib is not None, 'requires tblib to be installed') def test_was_successful_one_error(self): result = RemoteTestResult() - result.addError(None, ValueError('woops')) + result.addError(None, self._test_error_exc_info()) self.assertIs(result.wasSuccessful(), False) + @unittest.skipUnless(tblib is not None, 'requires tblib to be installed') def test_was_successful_one_failure(self): result = RemoteTestResult() - result.addFailure(None, ValueError('woops')) + result.addFailure(None, self._test_error_exc_info()) self.assertIs(result.wasSuccessful(), False) def test_picklable(self):