Skip to content

Commit 593de35

Browse files
committed
Ensure backend is set for subprocess'd tests.
This keeps them working even if the user has a backend set in their config that is not available in the test environment.
1 parent 3798e5f commit 593de35

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

lib/matplotlib/tests/test_determinism.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def test_determinism_check(objects, fmt, usetex):
100100
[sys.executable, "-R", "-c",
101101
f"from matplotlib.tests.test_determinism import _save_figure;"
102102
f"_save_figure({objects!r}, {fmt!r}, {usetex})"],
103-
env={**os.environ, "SOURCE_DATE_EPOCH": "946684800"})
103+
env={**os.environ, "SOURCE_DATE_EPOCH": "946684800",
104+
"MPLBACKEND": "Agg"})
104105
for _ in range(3)
105106
]
106107
for p in plots[1:]:
@@ -139,5 +140,6 @@ def test_determinism_source_date_epoch(fmt, string):
139140
[sys.executable, "-R", "-c",
140141
f"from matplotlib.tests.test_determinism import _save_figure; "
141142
f"_save_figure('', {fmt!r})"],
142-
env={**os.environ, "SOURCE_DATE_EPOCH": "946684800"})
143+
env={**os.environ, "SOURCE_DATE_EPOCH": "946684800",
144+
"MPLBACKEND": "Agg"})
143145
assert string in buf

lib/matplotlib/tests/test_matplotlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ def test_importable_with__OO():
5656
"import matplotlib.patches as mpatches"
5757
)
5858
cmd = [sys.executable, "-OO", "-c", program]
59-
assert subprocess.call(cmd) == 0
59+
assert subprocess.call(cmd, env={**os.environ, "MPLBACKEND": ""}) == 0

lib/matplotlib/tests/test_sphinxext.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for tinypages build using sphinx extensions."""
22

33
import filecmp
4+
import os
45
from pathlib import Path
56
from subprocess import Popen, PIPE
67
import sys
@@ -19,14 +20,14 @@ def test_tinypages(tmpdir):
1920
cmd = [sys.executable, '-msphinx', '-W', '-b', 'html',
2021
'-d', str(doctree_dir),
2122
str(Path(__file__).parent / 'tinypages'), str(html_dir)]
22-
proc = Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
23+
proc = Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True,
24+
env={**os.environ, "MPLBACKEND": ""})
2325
out, err = proc.communicate()
2426

2527
assert proc.returncode == 0, \
26-
"sphinx build failed with stdout:\n{}\nstderr:\n{}\n".format(out, err)
28+
f"sphinx build failed with stdout:\n{out}\nstderr:\n{err}\n"
2729
if err:
28-
pytest.fail("sphinx build emitted the following warnings:\n{}"
29-
.format(err))
30+
pytest.fail(f"sphinx build emitted the following warnings:\n{err}")
3031

3132
assert html_dir.is_dir()
3233

0 commit comments

Comments
 (0)