1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #35622 -- Made unittest ignore Django assertions in traceback frames.

Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
This commit is contained in:
Adam Johnson
2024-07-22 11:19:00 +01:00
committed by nessita
parent e1606d27b4
commit 9582745257
6 changed files with 42 additions and 1 deletions

View File

@@ -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):