diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py index 4b4766be0..163a3b65b 100644 --- a/sphinx/testing/fixtures.py +++ b/sphinx/testing/fixtures.py @@ -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)