Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d556f5

Browse files
committed
Issue #14135: Make sure tests don't leave the locale changed for any
category. Thanks to Westley Martinez for trying to fix the issue and Atsuo Ishimoto for an initial patch.
1 parent af504ca commit 2d556f5

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

Lib/test/regrtest.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
import faulthandler
128128
import io
129129
import json
130+
import locale
130131
import logging
131132
import os
132133
import platform
@@ -1061,7 +1062,7 @@ def __init__(self, testname, verbose=0, quiet=False):
10611062
'sys.warnoptions', 'threading._dangling',
10621063
'multiprocessing.process._dangling',
10631064
'sysconfig._CONFIG_VARS', 'sysconfig._INSTALL_SCHEMES',
1064-
'support.TESTFN',
1065+
'support.TESTFN', 'locale'
10651066
)
10661067

10671068
def get_sys_argv(self):
@@ -1230,6 +1231,14 @@ def restore_support_TESTFN(self, saved_value):
12301231
elif os.path.isdir(support.TESTFN):
12311232
shutil.rmtree(support.TESTFN)
12321233

1234+
_locale_categories = [getattr(locale, lc)
1235+
for lc in dir(locale) if lc.startswith('LC_')]
1236+
def get_locale(self):
1237+
return tuple(map(locale.getlocale, self._locale_categories))
1238+
def restore_locale(self, saved):
1239+
for category, setting in zip(self._locale_categories, saved):
1240+
locale.setlocale(category, setting)
1241+
12331242
def resource_info(self):
12341243
for name in self.resources:
12351244
method_suffix = name.replace('.', '_')

0 commit comments

Comments
 (0)