[Python-checkins] ensure deprecation warning from assertDictContainsSubset points at actual test code (#26497)

rhettinger webhook-mailer at python.org
Mon Nov 15 22:11:19 EST 2021


https://github.com/python/cpython/commit/7c99e434a9b3830698d52a62fe8641d480856ca9
commit: 7c99e434a9b3830698d52a62fe8641d480856ca9
branch: 3.10
author: Anthony Sottile <asottile at umich.edu>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2021-11-15T21:11:02-06:00
summary:

ensure deprecation warning from assertDictContainsSubset points at actual test code (#26497)

files:
A Misc/NEWS.d/next/Library/2021-06-02-16-39-42.bpo-44295.erg01m.rst
M Lib/unittest/case.py
M Lib/unittest/test/test_case.py

diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 607c7aecc7003..61003d0c6ead9 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -1146,7 +1146,8 @@ def assertDictEqual(self, d1, d2, msg=None):
     def assertDictContainsSubset(self, subset, dictionary, msg=None):
         """Checks whether dictionary is a superset of subset."""
         warnings.warn('assertDictContainsSubset is deprecated',
-                      DeprecationWarning)
+                      DeprecationWarning,
+                      stacklevel=2)
         missing = []
         mismatched = []
         for key, value in subset.items():
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py
index 35334851304d8..442651e1e4884 100644
--- a/Lib/unittest/test/test_case.py
+++ b/Lib/unittest/test/test_case.py
@@ -706,6 +706,10 @@ def testAssertDictContainsSubset(self):
             with self.assertRaises(self.failureException):
                 self.assertDictContainsSubset({'foo': one}, {'foo': '\uFFFD'})
 
+        with self.assertWarns(DeprecationWarning) as warninfo:
+            self.assertDictContainsSubset({}, {})
+        self.assertEqual(warninfo.warnings[0].filename, __file__)
+
     def testAssertEqual(self):
         equal_pairs = [
                 ((), ()),
diff --git a/Misc/NEWS.d/next/Library/2021-06-02-16-39-42.bpo-44295.erg01m.rst b/Misc/NEWS.d/next/Library/2021-06-02-16-39-42.bpo-44295.erg01m.rst
new file mode 100644
index 0000000000000..86501c15d86f4
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-06-02-16-39-42.bpo-44295.erg01m.rst
@@ -0,0 +1,2 @@
+Ensure deprecation warning from :func:`assertDictContainsSubset` points at
+calling code - by Anthony Sottile.



More information about the Python-checkins mailing list