]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
ensure deprecation warning from assertDictContainsSubset points at actual test code...
authorAnthony Sottile <asottile@umich.edu>
Tue, 16 Nov 2021 03:11:02 +0000 (22:11 -0500)
committerGitHub <noreply@github.com>
Tue, 16 Nov 2021 03:11:02 +0000 (21:11 -0600)
Lib/unittest/case.py
Lib/unittest/test/test_case.py
Misc/NEWS.d/next/Library/2021-06-02-16-39-42.bpo-44295.erg01m.rst [new file with mode: 0644]

index 607c7aecc700370cebca7f07ab9c388ba1145b7f..61003d0c6ead9351625b48cd1682eea223b98c50 100644 (file)
@@ -1146,7 +1146,8 @@ class TestCase(object):
     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():
index 35334851304d82bf54c2c42d0eba7d2424b3ad8f..442651e1e4884db3a11954aee21c22649699bd4f 100644 (file)
@@ -706,6 +706,10 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
             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 (file)
index 0000000..86501c1
--- /dev/null
@@ -0,0 +1,2 @@
+Ensure deprecation warning from :func:`assertDictContainsSubset` points at
+calling code - by Anthony Sottile.