@@ -1640,22 +1640,36 @@ def test_latex(self, is_latex, usetex, expected):
1640
1640
assert fmt .format_pct (50 , 100 ) == expected
1641
1641
1642
1642
1643
- def test_locale_comma ():
1644
- currentLocale = locale .getlocale ()
1643
+ def _impl_locale_comma ():
1645
1644
try :
1646
1645
locale .setlocale (locale .LC_ALL , 'de_DE.UTF-8' )
1647
- ticks = mticker .ScalarFormatter (useMathText = True , useLocale = True )
1648
- fmt = '$\\ mathdefault{%1.1f}$'
1649
- x = ticks ._format_maybe_minus_and_locale (fmt , 0.5 )
1650
- assert x == '$\\ mathdefault{0{,}5}$'
1651
- # Do not change , in the format string
1652
- fmt = ',$\\ mathdefault{,%1.1f},$'
1653
- x = ticks ._format_maybe_minus_and_locale (fmt , 0.5 )
1654
- assert x == ',$\\ mathdefault{,0{,}5},$'
1655
1646
except locale .Error :
1656
- pytest .skip ("Locale de_DE.UTF-8 is not supported on this machine" )
1657
- finally :
1658
- locale .setlocale (locale .LC_ALL , currentLocale )
1647
+ print ('SKIP: Locale de_DE.UTF-8 is not supported on this machine' )
1648
+ return
1649
+ ticks = mticker .ScalarFormatter (useMathText = True , useLocale = True )
1650
+ fmt = '$\\ mathdefault{%1.1f}$'
1651
+ x = ticks ._format_maybe_minus_and_locale (fmt , 0.5 )
1652
+ assert x == '$\\ mathdefault{0{,}5}$'
1653
+ # Do not change , in the format string
1654
+ fmt = ',$\\ mathdefault{,%1.1f},$'
1655
+ x = ticks ._format_maybe_minus_and_locale (fmt , 0.5 )
1656
+ assert x == ',$\\ mathdefault{,0{,}5},$'
1657
+
1658
+
1659
+ def test_locale_comma ():
1660
+ # On some systems/pytest versions, `pytest.skip` in an exception handler
1661
+ # does not skip, but is treated as an exception, so directly running this
1662
+ # test can incorrectly fail instead of skip.
1663
+ # Instead, run this test in a subprocess, which avoids the problem, and the
1664
+ # need to fix the locale after.
1665
+ proc = mpl .testing .subprocess_run_helper (_impl_locale_comma , timeout = 60 ,
1666
+ extra_env = {'MPLBACKEND' : 'Agg' })
1667
+ skip_msg = next ((line [len ('SKIP:' ):].strip ()
1668
+ for line in proc .stdout .splitlines ()
1669
+ if line .startswith ('SKIP:' )),
1670
+ '' )
1671
+ if skip_msg :
1672
+ pytest .skip (skip_msg )
1659
1673
1660
1674
1661
1675
def test_majformatter_type ():
0 commit comments