summaryrefslogtreecommitdiff
path: root/tests/test_utils
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2024-07-22 11:19:00 +0100
committernessita <124304+nessita@users.noreply.github.com>2024-08-08 21:34:01 -0300
commit95827452571eb976c4f0d5e9ac46843948dd5fe6 (patch)
tree99c85b6eb779323d3ecad30498e5cf0fd924c566 /tests/test_utils
parente1606d27b4fed653c80817f3a13cf8bc6f3163f0 (diff)
Fixed #35622 -- Made unittest ignore Django assertions in traceback frames.
Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
Diffstat (limited to 'tests/test_utils')
-rw-r--r--tests/test_utils/tests.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index cd64c087c4..60b65e309a 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -1,6 +1,7 @@
import os
import sys
import threading
+import traceback
import unittest
import warnings
from io import StringIO
@@ -1113,6 +1114,19 @@ class JSONEqualTests(SimpleTestCase):
with self.assertRaises(AssertionError):
self.assertJSONNotEqual(valid_json, invalid_json)
+ def test_method_frames_ignored_by_unittest(self):
+ try:
+ self.assertJSONEqual("1", "2")
+ except AssertionError:
+ exc_type, exc, tb = sys.exc_info()
+
+ result = unittest.TestResult()
+ result.addFailure(self, (exc_type, exc, tb))
+ stack = traceback.extract_tb(exc.__traceback__)
+ self.assertEqual(len(stack), 1)
+ # Top element in the stack is this method, not assertJSONEqual.
+ self.assertEqual(stack[-1].name, "test_method_frames_ignored_by_unittest")
+
class XMLEqualTests(SimpleTestCase):
def test_simple_equal(self):