From 53859e410c58b1e103cf61064d2b205e4917e01b Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Sun, 30 Apr 2023 15:49:55 +0100 Subject: [PATCH 1/2] Ensure test_calendar.CalendarTestCase.test_deprecation_warning consistently passes --- Lib/test/test_calendar.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index 03388e8c55d5a8..425533694e1cca 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -493,6 +493,7 @@ def test_format(self): class CalendarTestCase(unittest.TestCase): def test_deprecation_warning(self): + warnings.resetwarnings() with warnings.catch_warnings(record=True) as w: calendar.January self.assertEqual(len(w), 1) From a24e9b4bf56b41c657ce90696c385124ef5a4b55 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Sun, 30 Apr 2023 16:27:18 +0100 Subject: [PATCH 2/2] Use assertWarnsRegex --- Lib/test/test_calendar.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index 425533694e1cca..24e472b5fee828 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -493,12 +493,11 @@ def test_format(self): class CalendarTestCase(unittest.TestCase): def test_deprecation_warning(self): - warnings.resetwarnings() - with warnings.catch_warnings(record=True) as w: + with self.assertWarnsRegex( + DeprecationWarning, + "The 'January' attribute is deprecated, use 'JANUARY' instead" + ): calendar.January - self.assertEqual(len(w), 1) - self.assertEqual(w[0].category, DeprecationWarning) - self.assertIn("The 'January' attribute is deprecated, use 'JANUARY' instead", str(w[0].message)) def test_isleap(self): # Make sure that the return is right for a few years, and