[Python-checkins] bpo-37945: Fix test_locale.test_getsetlocale_issue1813() (GH-25110) (GH-25112)

ambv webhook-mailer at python.org
Wed Mar 31 07:52:23 EDT 2021


https://github.com/python/cpython/commit/fabdd25fe505c08da064425ea4d099fd2cef39d3
commit: fabdd25fe505c08da064425ea4d099fd2cef39d3
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2021-03-31T13:52:14+02:00
summary:

bpo-37945: Fix test_locale.test_getsetlocale_issue1813() (GH-25110) (GH-25112)

Skip the test if setlocale() fails.
(cherry picked from commit f3ab670fea75ebe177e3412a5ebe39263cd428e3)

Co-authored-by: Victor Stinner <vstinner at python.org>

files:
A Misc/NEWS.d/next/Tests/2021-03-31-11-38-42.bpo-37945.HTUYhv.rst
M Lib/test/test_locale.py

diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py
index 2863d200e25c2..375a1e4028631 100644
--- a/Lib/test/test_locale.py
+++ b/Lib/test/test_locale.py
@@ -563,7 +563,13 @@ def test_getsetlocale_issue1813(self):
         loc = locale.getlocale(locale.LC_CTYPE)
         if verbose:
             print('testing with %a' % (loc,), end=' ', flush=True)
-        locale.setlocale(locale.LC_CTYPE, loc)
+        try:
+            locale.setlocale(locale.LC_CTYPE, loc)
+        except locale.Error as exc:
+            # bpo-37945: setlocale(LC_CTYPE) fails with getlocale(LC_CTYPE)
+            # and the tr_TR locale on Windows. getlocale() builds a locale
+            # which is not recognize by setlocale().
+            self.skipTest(f"setlocale(LC_CTYPE, {loc!r}) failed: {exc!r}")
         self.assertEqual(loc, locale.getlocale(locale.LC_CTYPE))
 
     def test_invalid_locale_format_in_localetuple(self):
diff --git a/Misc/NEWS.d/next/Tests/2021-03-31-11-38-42.bpo-37945.HTUYhv.rst b/Misc/NEWS.d/next/Tests/2021-03-31-11-38-42.bpo-37945.HTUYhv.rst
new file mode 100644
index 0000000000000..e1c95f63bf7c7
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2021-03-31-11-38-42.bpo-37945.HTUYhv.rst
@@ -0,0 +1,2 @@
+Fix test_getsetlocale_issue1813() of test_locale: skip the test if
+``setlocale()`` fails. Patch by Victor Stinner.



More information about the Python-checkins mailing list