From 16fad2e00644fbe2a9e751777a7ffbea641440c8 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 4 Sep 2024 22:20:25 -0400 Subject: [PATCH] TST: Fix test_pickle_load_from_subprocess in a dirty tree For a ditry tree, `setuptools-scm` adds the date to the end of the version. This test runs a subprocess and `subprocess_run_helper` will set `SOURCE_DATE_EPOCH=0`, which forces the date to be 1970-01-01, triggering a mismatched version warning on unpickle. Since we aren't testing the version-compatibility warning, set `SETUPTOOLS_SCM_PRETEND_VERSION_FOR_MATPLOTLIB` in the subprocess call so that versions match. Also, set the `dist_name` parameter when querying setuptools-scm or it won't check that environment variable. --- lib/matplotlib/__init__.py | 1 + lib/matplotlib/tests/test_pickle.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 13bfa81d9ffa..b20af9108bd0 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -225,6 +225,7 @@ def _get_version(): else: return setuptools_scm.get_version( root=root, + dist_name="matplotlib", version_scheme="release-branch-semver", local_scheme="node-and-date", fallback_version=_version.version, diff --git a/lib/matplotlib/tests/test_pickle.py b/lib/matplotlib/tests/test_pickle.py index 1474a67d28aa..8bb7ef9deb54 100644 --- a/lib/matplotlib/tests/test_pickle.py +++ b/lib/matplotlib/tests/test_pickle.py @@ -150,7 +150,15 @@ def test_pickle_load_from_subprocess(fig_test, fig_ref, tmp_path): proc = subprocess_run_helper( _pickle_load_subprocess, timeout=60, - extra_env={'PICKLE_FILE_PATH': str(fp), 'MPLBACKEND': 'Agg'} + extra_env={ + "PICKLE_FILE_PATH": str(fp), + "MPLBACKEND": "Agg", + # subprocess_run_helper will set SOURCE_DATE_EPOCH=0, so for a dirty tree, + # the version will have the date 19700101. As we aren't trying to test the + # version compatibility warning, force setuptools-scm to use the same + # version as us. + "SETUPTOOLS_SCM_PRETEND_VERSION_FOR_MATPLOTLIB": mpl.__version__, + }, ) loaded_fig = pickle.loads(ast.literal_eval(proc.stdout))