From 820ebb2113f36b82c88bf1fc054a129857e2db87 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Sun, 29 Oct 2023 20:29:22 +0000 Subject: [PATCH] test: fix Sphinx 7 --- tests/test_sphinx.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_sphinx.py b/tests/test_sphinx.py index e88884f..9620d80 100644 --- a/tests/test_sphinx.py +++ b/tests/test_sphinx.py @@ -4,6 +4,7 @@ import pytest from sphinx.testing.path import path as sphinx_path from sphinx.testing.util import SphinxTestApp +from sphinx import version_info as sphinx_version_info from sphinx_external_toc.tools import create_site_from_toc @@ -47,7 +48,16 @@ def outdir(self): @pytest.fixture() def sphinx_build_factory(make_app): def _func(src_path: Path, **kwargs) -> SphinxBuild: - app = make_app(srcdir=sphinx_path(os.path.abspath(str(src_path))), **kwargs) + # For compatibility with multiple versions of sphinx, convert pathlib.Path to + # sphinx.testing.path.path here. + if sphinx_version_info >= (7, 2): + app_srcdir = src_path + else: + from sphinx.testing.path import path + + app_srcdir = path(os.fspath(src_path)) + + app = make_app(srcdir=app_srcdir, **kwargs) return SphinxBuild(app, src_path) yield _func