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

Skip to content

Commit 64cda24

Browse files
authored
TST: always force the SETUPTOOLS_SCM version in test subprocesses (#30947)
* TST: always force the SETUPTOOLS_SCM version in test subprocesses This will reduce the number of (sub)subprocess calls we make by at least one per subprocess test. This may help reduce resource contention on CI that causes flaky tests.
1 parent f7d261a commit 64cda24

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

lib/matplotlib/testing/__init__.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,26 @@ def subprocess_run_helper(func, *args, timeout, extra_env=None):
151151
f"_module = importlib.util.module_from_spec(_spec);"
152152
f"_spec.loader.exec_module(_module);"
153153
f"_module.{target}()",
154-
*args
154+
*args,
155155
],
156-
env={**os.environ, "SOURCE_DATE_EPOCH": "0", **(extra_env or {})},
157-
timeout=timeout, check=True,
156+
env={
157+
**os.environ,
158+
"SOURCE_DATE_EPOCH": "0",
159+
# subprocess_run_helper sets SOURCE_DATE_EPOCH=0 above, so for a dirty tree,
160+
# the version will have the date 19700101 which breaks pickle tests with a
161+
# warning if the working tree is dirty.
162+
#
163+
# This will also avoid at least one additional subprocess call for
164+
# setuptools-scm query git, so we tell the subprocess what version
165+
# to report as the test process.
166+
"SETUPTOOLS_SCM_PRETEND_VERSION_FOR_MATPLOTLIB": mpl.__version__,
167+
**(extra_env or {}),
168+
},
169+
timeout=timeout,
170+
check=True,
158171
stdout=subprocess.PIPE,
159172
stderr=subprocess.PIPE,
160-
text=True
173+
text=True,
161174
)
162175
return proc
163176

lib/matplotlib/tests/test_pickle.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,7 @@ def test_pickle_load_from_subprocess(fig_test, fig_ref, tmp_path):
150150
proc = subprocess_run_helper(
151151
_pickle_load_subprocess,
152152
timeout=60,
153-
extra_env={
154-
"PICKLE_FILE_PATH": str(fp),
155-
"MPLBACKEND": "Agg",
156-
# subprocess_run_helper will set SOURCE_DATE_EPOCH=0, so for a dirty tree,
157-
# the version will have the date 19700101. As we aren't trying to test the
158-
# version compatibility warning, force setuptools-scm to use the same
159-
# version as us.
160-
"SETUPTOOLS_SCM_PRETEND_VERSION_FOR_MATPLOTLIB": mpl.__version__,
161-
},
153+
extra_env={"PICKLE_FILE_PATH": str(fp), "MPLBACKEND": "Agg"},
162154
)
163155

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

0 commit comments

Comments
 (0)