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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user