Skip to content

Commit d4f2440

Browse files
committed
Make the sphinx extension tests more robust to manually building the docs in tinypages
The tests now don't copy any of the build files, meaning the tests should pass even if tinypages has stale build state from a manual build.
1 parent 550e382 commit d4f2440

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
_build/
2+
doctrees/
3+
plot_directive/

lib/matplotlib/tests/test_sphinxext.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616
tinypages = Path(__file__).parent / 'data/tinypages'
1717

1818

19+
def _ignore_build_artifacts(dir, files):
20+
"""
21+
Ignore function for shutil.copytree to exclude build artifacts.
22+
23+
This prevents stale build artifacts from the source tinypages directory
24+
from being copied to test directories, which could cause inconsistent
25+
test results due to cached or outdated files.
26+
"""
27+
return {'_build', 'doctrees', 'plot_directive'} & set(files)
28+
29+
1930
def build_sphinx_html(source_dir, doctree_dir, html_dir, extra_args=None):
2031
# Build the pages with warnings turned into errors
2132
extra_args = [] if extra_args is None else extra_args
@@ -40,7 +51,8 @@ def build_sphinx_html(source_dir, doctree_dir, html_dir, extra_args=None):
4051

4152

4253
def test_tinypages(tmp_path):
43-
shutil.copytree(tinypages, tmp_path, dirs_exist_ok=True)
54+
shutil.copytree(tinypages, tmp_path, dirs_exist_ok=True,
55+
ignore=_ignore_build_artifacts)
4456
html_dir = tmp_path / '_build' / 'html'
4557
img_dir = html_dir / '_images'
4658
doctree_dir = tmp_path / 'doctrees'
@@ -204,11 +216,13 @@ def test_plot_html_show_source_link_custom_basename(tmp_path):
204216

205217

206218
def test_srcset_version(tmp_path):
219+
shutil.copytree(tinypages, tmp_path, dirs_exist_ok=True,
220+
ignore=_ignore_build_artifacts)
207221
html_dir = tmp_path / '_build' / 'html'
208222
img_dir = html_dir / '_images'
209223
doctree_dir = tmp_path / 'doctrees'
210224

211-
build_sphinx_html(tinypages, doctree_dir, html_dir,
225+
build_sphinx_html(tmp_path, doctree_dir, html_dir,
212226
extra_args=['-D', 'plot_srcset=2x'])
213227

214228
def plot_file(num, suff=''):

0 commit comments

Comments
 (0)