Skip to content

Commit 184e480

Browse files
author
Sylvain MARIE
committed
Improved readability of fixture overridden_locale as per code review
1 parent d175c36 commit 184e480

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

pandas/conftest.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -1219,23 +1219,18 @@ def overridden_locale(request):
12191219
If a locale cannot be set (because it is not available on the host)
12201220
the test is skipped.
12211221
"""
1222-
old = locale.setlocale(locale.LC_ALL)
12231222
target = request.param
12241223
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)
12271226
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
12341231
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.")
12391234

12401235

12411236
# ----------------------------------------------------------------

0 commit comments

Comments
 (0)