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

Skip to content

Commit 227825e

Browse files
authored
Merge pull request #26688 from meeseeksmachine/auto-backport-of-pr-26680-on-v3.8.x
Backport PR #26680 on branch v3.8.x (Fix flaky CI tests)
2 parents 1395aa7 + c476f17 commit 227825e

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def _test_figure_leak():
660660
reason="appveyor tests fail; gh-22988 suggests reworking")
661661
@pytest.mark.parametrize("env", _get_testable_interactive_backends())
662662
@pytest.mark.parametrize("time_mem", [(0.0, 2_000_000), (0.1, 30_000_000)])
663-
def test_figure_leak_20490(env, time_mem):
663+
def test_figure_leak_20490(env, time_mem, request):
664664
pytest.importorskip("psutil", reason="psutil needed to run this test")
665665

666666
# We haven't yet directly identified the leaks so test with a memory growth
@@ -669,9 +669,10 @@ def test_figure_leak_20490(env, time_mem):
669669
if env["MPLBACKEND"] == "wx":
670670
pytest.skip("wx backend is deprecated; tests failed on appveyor")
671671

672-
if env["MPLBACKEND"] == "macosx" or (
673-
env["MPLBACKEND"] == "tkagg" and sys.platform == 'darwin'
674-
):
672+
if env["MPLBACKEND"] == "macosx":
673+
request.node.add_marker(pytest.mark.xfail(reason="macosx backend is leaky"))
674+
675+
if env["MPLBACKEND"] == "tkagg" and sys.platform == "darwin":
675676
acceptable_memory_leakage += 11_000_000
676677

677678
result = _run_helper(
@@ -815,12 +816,12 @@ def custom_signal_handler(signum, frame):
815816
('show', {'block': True}),
816817
('pause', {'interval': 10})
817818
])
818-
def test_other_signal_before_sigint(env, target, kwargs):
819+
def test_other_signal_before_sigint(env, target, kwargs, request):
819820
backend = env.get("MPLBACKEND")
820821
if not backend.startswith(("qt", "macosx")):
821822
pytest.skip("SIGINT currently only tested on qt and macosx")
822-
if backend == "macosx" and target == "show":
823-
pytest.xfail("test currently failing for macosx + show()")
823+
if backend == "macosx":
824+
request.node.add_marker(pytest.mark.xfail(reason="macosx backend is buggy"))
824825
proc = _WaitForStringPopen(
825826
[sys.executable, "-c",
826827
inspect.getsource(_test_other_signal_before_sigint_impl) +

lib/matplotlib/tests/test_pickle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def test_pickle_load_from_subprocess(fig_test, fig_ref, tmp_path):
143143
proc = subprocess_run_helper(
144144
_pickle_load_subprocess,
145145
timeout=60,
146-
extra_env={'PICKLE_FILE_PATH': str(fp)}
146+
extra_env={'PICKLE_FILE_PATH': str(fp), 'MPLBACKEND': 'Agg'}
147147
)
148148

149149
loaded_fig = pickle.loads(ast.literal_eval(proc.stdout))

lib/matplotlib/tests/test_ticker.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,22 +1640,36 @@ def test_latex(self, is_latex, usetex, expected):
16401640
assert fmt.format_pct(50, 100) == expected
16411641

16421642

1643-
def test_locale_comma():
1644-
currentLocale = locale.getlocale()
1643+
def _impl_locale_comma():
16451644
try:
16461645
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},$'
16551646
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)
16591673

16601674

16611675
def test_majformatter_type():

0 commit comments

Comments
 (0)