Skip to content

Commit 7c99e43

Browse files
authored
ensure deprecation warning from assertDictContainsSubset points at actual test code (#26497)
1 parent 94dad5e commit 7c99e43

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Lib/unittest/case.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,8 @@ def assertDictEqual(self, d1, d2, msg=None):
11461146
def assertDictContainsSubset(self, subset, dictionary, msg=None):
11471147
"""Checks whether dictionary is a superset of subset."""
11481148
warnings.warn('assertDictContainsSubset is deprecated',
1149-
DeprecationWarning)
1149+
DeprecationWarning,
1150+
stacklevel=2)
11501151
missing = []
11511152
mismatched = []
11521153
for key, value in subset.items():

Lib/unittest/test/test_case.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,10 @@ def testAssertDictContainsSubset(self):
706706
with self.assertRaises(self.failureException):
707707
self.assertDictContainsSubset({'foo': one}, {'foo': '\uFFFD'})
708708

709+
with self.assertWarns(DeprecationWarning) as warninfo:
710+
self.assertDictContainsSubset({}, {})
711+
self.assertEqual(warninfo.warnings[0].filename, __file__)
712+
709713
def testAssertEqual(self):
710714
equal_pairs = [
711715
((), ()),
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Ensure deprecation warning from :func:`assertDictContainsSubset` points at
2+
calling code - by Anthony Sottile.

0 commit comments

Comments
 (0)