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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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,

0 commit comments

Comments
 (0)