File tree 1 file changed +8
-13
lines changed
1 file changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -1219,23 +1219,18 @@ def overridden_locale(request):
1219
1219
If a locale cannot be set (because it is not available on the host)
1220
1220
the test is skipped.
1221
1221
"""
1222
- old = locale .setlocale (locale .LC_ALL )
1223
1222
target = request .param
1224
1223
if target is None :
1225
- # Current locale - don't change
1226
- yield old
1224
+ # Use current locale for this test.
1225
+ yield locale . setlocale ( locale . LC_ALL )
1227
1226
else :
1228
- try :
1229
- # Try changing the locale.
1230
- locale .setlocale (locale .LC_ALL , target )
1231
- except locale .Error as e :
1232
- # Not available on this host. Skip test.
1233
- pytest .skip (f"Skipping as locale cannot be set. { type (e ).__name__ } : { e } " )
1227
+ if tm .can_set_locale (target , locale .LC_ALL ):
1228
+ # Change locale temporarily for this test.
1229
+ with tm .set_locale (target , locale .LC_ALL ):
1230
+ yield target
1234
1231
else :
1235
- # Run test with the temporary local
1236
- yield target
1237
- # Set back to normal
1238
- locale .setlocale (locale .LC_ALL , old )
1232
+ # Not available on this host. Skip test.
1233
+ pytest .skip (f"Skipping as locale { repr (locale )} cannot be set on host." )
1239
1234
1240
1235
1241
1236
# ----------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments