Improve directory handling in `app_params()`

This commit is contained in:
Adam Turner 2025-01-31 17:25:13 +00:00
parent 17b8241585
commit d24ffe2949

View File

@ -73,8 +73,8 @@ def app_params(
request: Any, request: Any,
test_params: dict[str, Any], test_params: dict[str, Any],
shared_result: SharedResult, shared_result: SharedResult,
sphinx_test_tempdir: str, sphinx_test_tempdir: Path,
rootdir: Path, rootdir: Path | None,
) -> _app_params: ) -> _app_params:
"""Parameters that are specified by 'pytest.mark.sphinx' for """Parameters that are specified by 'pytest.mark.sphinx' for
sphinx.application.Sphinx initialization sphinx.application.Sphinx initialization
@ -102,13 +102,17 @@ def app_params(
# ##### prepare Application params # ##### prepare Application params
testroot = kwargs.pop('testroot', 'root') test_root = kwargs.pop('testroot', 'root')
kwargs['srcdir'] = srcdir = sphinx_test_tempdir / kwargs.get('srcdir', testroot) kwargs['srcdir'] = srcdir = sphinx_test_tempdir / kwargs.get('srcdir', test_root)
# special support for sphinx/tests # special support for sphinx/tests
if rootdir and not srcdir.exists(): if rootdir is not None:
testroot_path = rootdir / ('test-' + testroot) test_root_path = rootdir / f'test-{test_root}'
shutil.copytree(testroot_path, srcdir) if test_root_path.is_dir() and not srcdir.exists():
shutil.copytree(test_root_path, srcdir)
# always write to the temporary directory
kwargs.setdefault('builddir', srcdir / '_build')
return _app_params(args, kwargs) return _app_params(args, kwargs)