1616tinypages = 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+
1930def 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
4253def 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
206218def 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