From: Anthony Sottile Date: Tue, 16 Nov 2021 03:11:02 +0000 (-0500) Subject: ensure deprecation warning from assertDictContainsSubset points at actual test code... X-Git-Tag: v3.10.1~67 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7c99e434a9b3830698d52a62fe8641d480856ca9;p=thirdparty%2FPython%2Fcpython.git ensure deprecation warning from assertDictContainsSubset points at actual test code (#26497) --- diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 607c7aecc700..61003d0c6ead 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -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(): diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index 35334851304d..442651e1e488 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -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 index 000000000000..86501c15d86f --- /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.