Skip to content

Commit 40f20c3

Browse files
committed
FIX: Move all tests using subprocess to the same worker on windows
This is a somewhat wild guess based on #29797 (comment) > which makes me think we are somehow crossing state what launching the subprocesses. Using the `xdist_group` with `--dist=loadgroup` should put all tests of that group to the same worker according to https://pytest-xdist.readthedocs.io/en/stable/distribution.html. I've only added `--dist=loadgroup` to the windows pipelines, so tests on other systems are not affected at all. The first test is to see whether this works in the PR. - But to be sure, it think we would need to put this on master and monitor whether the timeouts disappear.
1 parent 919d9e9 commit 40f20c3

17 files changed

+34
-0
lines changed

azure-pipelines.yml

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ stages:
149149
150150
PYTHONFAULTHANDLER=1 pytest -rfEsXR -n 2 \
151151
--maxfail=50 --timeout=300 --durations=25 \
152+
--dist=loadgroup \
152153
--junitxml=junit/test-results.xml --cov-report=xml --cov=lib
153154
154155
if [[ $VS_VER == 2022 ]]; then

lib/matplotlib/tests/test_backend_inline.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
pytest.importorskip('matplotlib_inline')
1313

1414

15+
@pytest.mark.xdist_group(name="subprocess")
1516
def test_ipynb():
1617
nb_path = Path(__file__).parent / 'test_inline_01.ipynb'
1718

lib/matplotlib/tests/test_backend_macosx.py

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def _test_cached_renderer():
2525

2626

2727
@pytest.mark.backend('macosx', skip_on_importerror=True)
28+
@pytest.mark.xdist_group(name="subprocess")
2829
def test_cached_renderer():
2930
subprocess_run_helper(_test_cached_renderer, timeout=_test_timeout,
3031
extra_env={"MPLBACKEND": "macosx"})
@@ -55,13 +56,15 @@ def new_choose_save_file(title, directory, filename):
5556

5657

5758
@pytest.mark.backend('macosx', skip_on_importerror=True)
59+
@pytest.mark.xdist_group(name="subprocess")
5860
def test_savefig_rcparam(tmp_path):
5961
subprocess_run_helper(
6062
_test_savefig_rcparam, timeout=_test_timeout,
6163
extra_env={"MPLBACKEND": "macosx", "TEST_SAVEFIG_PATH": tmp_path})
6264

6365

6466
@pytest.mark.backend('macosx', skip_on_importerror=True)
67+
@pytest.mark.xdist_group(name="subprocess")
6568
def test_ipython():
6669
from matplotlib.testing import ipython_in_subprocess
6770
ipython_in_subprocess("osx", {(8, 24): "macosx", (7, 0): "MacOSX"})
@@ -81,6 +84,7 @@ def _test_save_figure_return():
8184

8285

8386
@pytest.mark.backend('macosx', skip_on_importerror=True)
87+
@pytest.mark.xdist_group(name="subprocess")
8488
def test_save_figure_return():
8589
subprocess_run_helper(_test_save_figure_return, timeout=_test_timeout,
8690
extra_env={"MPLBACKEND": "macosx"})

lib/matplotlib/tests/test_backend_nbagg.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# From https://blog.thedataincubator.com/2016/06/testing-jupyter-notebooks/
1414

1515

16+
@pytest.mark.xdist_group(name="subprocess")
1617
def test_ipynb():
1718
nb_path = Path(__file__).parent / 'test_nbagg_01.ipynb'
1819

lib/matplotlib/tests/test_backend_tk.py

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def _isolated_tk_test(success_count, func=None):
4343
sys.platform == 'darwin' and sys.version_info[:2] < (3, 11),
4444
reason='Tk version mismatch on Azure macOS CI'
4545
)
46+
@pytest.mark.xdist_group(name="subprocess")
4647
@functools.wraps(func)
4748
def test_func():
4849
# even if the package exists, may not actually be importable this can

lib/matplotlib/tests/test_backend_webagg.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
@pytest.mark.parametrize("backend", ["webagg", "nbagg"])
10+
@pytest.mark.xdist_group(name="subprocess")
1011
def test_webagg_fallback(backend):
1112
pytest.importorskip("tornado")
1213
if backend == "nbagg":

lib/matplotlib/tests/test_basic.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import sys
44
import textwrap
55

6+
import pytest
7+
68
from matplotlib.testing import subprocess_run_for_testing
79

810

@@ -28,6 +30,7 @@ def test_override_builtins():
2830
assert overridden <= ok_to_override
2931

3032

33+
@pytest.mark.xdist_group(name="subprocess")
3134
def test_lazy_imports():
3235
source = textwrap.dedent("""
3336
import sys

lib/matplotlib/tests/test_determinism.py

+2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def draw(self, renderer=None):
154154
pytest.param("mhip", "svg", True, marks=needs_usetex),
155155
]
156156
)
157+
@pytest.mark.xdist_group(name="subprocess")
157158
def test_determinism_check(objects, fmt, usetex):
158159
"""
159160
Output three times the same graphs and checks that the outputs are exactly
@@ -195,6 +196,7 @@ def test_determinism_check(objects, fmt, usetex):
195196
("ps", b"%%CreationDate: Sat Jan 01 00:00:00 2000"),
196197
]
197198
)
199+
@pytest.mark.xdist_group(name="subprocess")
198200
def test_determinism_source_date_epoch(fmt, string):
199201
"""
200202
Test SOURCE_DATE_EPOCH support. Output a document with the environment

lib/matplotlib/tests/test_font_manager.py

+2
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,14 @@ def bad_idea(n):
282282
raise RuntimeError("thread failed to join")
283283

284284

285+
@pytest.mark.xdist_group(name="subprocess")
285286
def test_fontcache_thread_safe():
286287
pytest.importorskip('threading')
287288

288289
subprocess_run_helper(_test_threading, timeout=10)
289290

290291

292+
@pytest.mark.xdist_group(name="subprocess")
291293
def test_lockfilefailure(tmp_path):
292294
# The logic here:
293295
# 1. get a temp directory from pytest

lib/matplotlib/tests/test_matplotlib.py

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_parse_to_version_info(version_str, version_tuple):
2222
reason="chmod() doesn't work as is on Windows")
2323
@pytest.mark.skipif(sys.platform != "win32" and os.geteuid() == 0,
2424
reason="chmod() doesn't work as root")
25+
@pytest.mark.xdist_group(name="subprocess")
2526
def test_tmpconfigdir_warning(tmp_path):
2627
"""Test that a warning is emitted if a temporary configdir must be used."""
2728
mode = os.stat(tmp_path).st_mode
@@ -36,6 +37,7 @@ def test_tmpconfigdir_warning(tmp_path):
3637
os.chmod(tmp_path, mode)
3738

3839

40+
@pytest.mark.xdist_group(name="subprocess")
3941
def test_importable_with_no_home(tmp_path):
4042
subprocess_run_for_testing(
4143
[sys.executable, "-c",
@@ -65,6 +67,7 @@ def parse(key):
6567
set(backend_registry.list_builtin(BackendFilter.NON_INTERACTIVE)))
6668

6769

70+
@pytest.mark.xdist_group(name="subprocess")
6871
def test_importable_with__OO():
6972
"""
7073
When using -OO or export PYTHONOPTIMIZE=2, docstrings are discarded,

lib/matplotlib/tests/test_pickle.py

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def _pickle_load_subprocess():
136136

137137

138138
@mpl.style.context("default")
139+
@pytest.mark.xdist_group(name="subprocess")
139140
@check_figures_equal()
140141
def test_pickle_load_from_subprocess(fig_test, fig_ref, tmp_path):
141142
_generate_complete_test_figure(fig_ref)
@@ -331,6 +332,7 @@ def _test_axeswidget_interactive():
331332
sys.platform == 'darwin' and sys.version_info[:2] < (3, 11),
332333
reason='Tk version mismatch on Azure macOS CI'
333334
)
335+
@pytest.mark.xdist_group(name="subprocess")
334336
def test_axeswidget_interactive():
335337
subprocess_run_helper(
336338
_test_axeswidget_interactive,

lib/matplotlib/tests/test_preprocess_data.py

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def funcy(ax, x, y, z, t=None):
245245
funcy.__doc__)
246246

247247

248+
@pytest.mark.xdist_group(name="subprocess")
248249
def test_data_parameter_replacement():
249250
"""
250251
Test that the docstring contains the correct *data* parameter stub

lib/matplotlib/tests/test_pyplot.py

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from matplotlib import pyplot as plt
1212

1313

14+
@pytest.mark.xdist_group(name="subprocess")
1415
def test_pyplot_up_to_date(tmp_path):
1516
pytest.importorskip("black")
1617

@@ -348,6 +349,7 @@ def test_set_current_axes_on_subfigure():
348349
assert plt.gca() == ax
349350

350351

352+
@pytest.mark.xdist_group(name="subprocess")
351353
def test_pylab_integration():
352354
IPython = pytest.importorskip("IPython")
353355
mpl.testing.subprocess_run_helper(

lib/matplotlib/tests/test_rcparams.py

+3
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ def test_rcparams_reset_after_fail():
529529

530530

531531
@pytest.mark.skipif(sys.platform != "linux", reason="Linux only")
532+
@pytest.mark.xdist_group(name="subprocess")
532533
def test_backend_fallback_headless_invalid_backend(tmp_path):
533534
env = {**os.environ,
534535
"DISPLAY": "", "WAYLAND_DISPLAY": "",
@@ -546,6 +547,7 @@ def test_backend_fallback_headless_invalid_backend(tmp_path):
546547

547548

548549
@pytest.mark.skipif(sys.platform != "linux", reason="Linux only")
550+
@pytest.mark.xdist_group(name="subprocess")
549551
def test_backend_fallback_headless_auto_backend(tmp_path):
550552
# specify a headless mpl environment, but request a graphical (tk) backend
551553
env = {**os.environ,
@@ -570,6 +572,7 @@ def test_backend_fallback_headless_auto_backend(tmp_path):
570572
@pytest.mark.skipif(
571573
sys.platform == "linux" and not _c_internal_utils.xdisplay_is_valid(),
572574
reason="headless")
575+
@pytest.mark.xdist_group(name="subprocess")
573576
def test_backend_fallback_headful(tmp_path):
574577
if parse_version(pytest.__version__) >= parse_version('8.2.0'):
575578
pytest_kwargs = dict(exc_type=ImportError)

lib/matplotlib/tests/test_sphinxext.py

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def build_sphinx_html(source_dir, doctree_dir, html_dir, extra_args=None):
3232
assert html_dir.is_dir()
3333

3434

35+
@pytest.mark.xdist_group(name="subprocess")
3536
def test_tinypages(tmp_path):
3637
shutil.copytree(Path(__file__).parent / 'tinypages', tmp_path,
3738
dirs_exist_ok=True)
@@ -124,6 +125,7 @@ def plot_directive_file(num):
124125
assert filecmp.cmp(range_6, plot_file(5))
125126

126127

128+
@pytest.mark.xdist_group(name="subprocess")
127129
def test_plot_html_show_source_link(tmp_path):
128130
parent = Path(__file__).parent
129131
shutil.copyfile(parent / 'tinypages/conf.py', tmp_path / 'conf.py')
@@ -147,6 +149,7 @@ def test_plot_html_show_source_link(tmp_path):
147149

148150

149151
@pytest.mark.parametrize('plot_html_show_source_link', [0, 1])
152+
@pytest.mark.xdist_group(name="subprocess")
150153
def test_show_source_link_true(tmp_path, plot_html_show_source_link):
151154
# Test that a source link is generated if :show-source-link: is true,
152155
# whether or not plot_html_show_source_link is true.
@@ -167,6 +170,7 @@ def test_show_source_link_true(tmp_path, plot_html_show_source_link):
167170

168171

169172
@pytest.mark.parametrize('plot_html_show_source_link', [0, 1])
173+
@pytest.mark.xdist_group(name="subprocess")
170174
def test_show_source_link_false(tmp_path, plot_html_show_source_link):
171175
# Test that a source link is NOT generated if :show-source-link: is false,
172176
# whether or not plot_html_show_source_link is true.
@@ -186,6 +190,7 @@ def test_show_source_link_false(tmp_path, plot_html_show_source_link):
186190
assert len(list(html_dir.glob("**/index-1.py"))) == 0
187191

188192

193+
@pytest.mark.xdist_group(name="subprocess")
189194
def test_srcset_version(tmp_path):
190195
shutil.copytree(Path(__file__).parent / 'tinypages', tmp_path,
191196
dirs_exist_ok=True)

lib/matplotlib/tests/test_texmanager.py

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def test_unicode_characters():
6464

6565

6666
@needs_usetex
67+
@pytest.mark.xdist_group(name="subprocess")
6768
def test_openin_any_paranoid():
6869
completed = subprocess_run_for_testing(
6970
[sys.executable, "-c",

lib/matplotlib/tests/test_ticker.py

+1
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,7 @@ def _impl_locale_comma():
17661766
assert x == '0,5'
17671767

17681768

1769+
@pytest.mark.xdist_group(name="subprocess")
17691770
def test_locale_comma():
17701771
# On some systems/pytest versions, `pytest.skip` in an exception handler
17711772
# does not skip, but is treated as an exception, so directly running this

0 commit comments

Comments
 (0)