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,
test_params: dict[str, Any],
shared_result: SharedResult,
sphinx_test_tempdir: str,
rootdir: Path,
sphinx_test_tempdir: Path,
rootdir: Path | None,
) -> _app_params:
"""Parameters that are specified by 'pytest.mark.sphinx' for
sphinx.application.Sphinx initialization
@ -102,13 +102,17 @@ def app_params(
# ##### prepare Application params
testroot = kwargs.pop('testroot', 'root')
kwargs['srcdir'] = srcdir = sphinx_test_tempdir / kwargs.get('srcdir', testroot)
test_root = kwargs.pop('testroot', 'root')
kwargs['srcdir'] = srcdir = sphinx_test_tempdir / kwargs.get('srcdir', test_root)
# special support for sphinx/tests
if rootdir and not srcdir.exists():
testroot_path = rootdir / ('test-' + testroot)
shutil.copytree(testroot_path, srcdir)
if rootdir is not None:
test_root_path = rootdir / f'test-{test_root}'
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)