summaryrefslogtreecommitdiff
path: root/django/test
diff options
context:
space:
mode:
authorDavid Winiecki <david.winiecki@gmail.com>2024-10-16 15:40:26 -0700
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-11-06 17:14:41 +0100
commit661dfdd59809f4abd5077f7a2529735d07b98ba4 (patch)
tree6a5ad9266411e7c684b72202662409b56c84438e /django/test
parent41da8a4f5a55c11fb28d2a172a7ad2cff53ca9ec (diff)
Fixed #35849 -- Made ParallelTestSuite report correct error location.
Diffstat (limited to 'django/test')
-rw-r--r--django/test/runner.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/django/test/runner.py b/django/test/runner.py
index 3912273b61..a52c52fe21 100644
--- a/django/test/runner.py
+++ b/django/test/runner.py
@@ -12,6 +12,7 @@ import random
import sys
import textwrap
import unittest
+import unittest.suite
from collections import defaultdict
from contextlib import contextmanager
from importlib import import_module
@@ -292,7 +293,15 @@ failure and get a correct traceback.
def addError(self, test, err):
self.check_picklable(test, err)
- self.events.append(("addError", self.test_index, err))
+
+ event_occurred_before_first_test = self.test_index == -1
+ if event_occurred_before_first_test and isinstance(
+ test, unittest.suite._ErrorHolder
+ ):
+ self.events.append(("addError", self.test_index, test.id(), err))
+ else:
+ self.events.append(("addError", self.test_index, err))
+
super().addError(test, err)
def addFailure(self, test, err):
@@ -558,8 +567,19 @@ class ParallelTestSuite(unittest.TestSuite):
handler = getattr(result, event_name, None)
if handler is None:
return
- test = tests[event[1]]
- args = event[2:]
+ test_index = event[1]
+ event_occurred_before_first_test = test_index == -1
+ if (
+ event_name == "addError"
+ and event_occurred_before_first_test
+ and len(event) >= 4
+ ):
+ test_id = event[2]
+ test = unittest.suite._ErrorHolder(test_id)
+ args = event[3:]
+ else:
+ test = tests[test_index]
+ args = event[2:]
handler(test, *args)
def __iter__(self):