From 2be6cce0ff143d0359ef9855f397bb98739e504e Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Thu, 28 Sep 2023 15:45:45 +0200 Subject: [PATCH] FIX: import `sphinx.testing.path` for lower Sphinx versions --- pyproject.toml | 1 + setup.cfg | 1 + tests/conftest.py | 27 ++++++++++++++++++++++----- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0a7881b..120a884 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -81,6 +81,7 @@ reportUnknownArgumentType = false reportUnknownMemberType = false reportUnknownParameterType = false reportUnknownVariableType = false +reportUntypedFunctionDecorator = false reportUnusedClass = true reportUnusedFunction = true reportUnusedImport = true diff --git a/setup.cfg b/setup.cfg index 65fafb3..c5172c4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -50,6 +50,7 @@ packages = find: [options.extras_require] test = + importlib-metadata; python_version <"3.8.0" pyquery # for checking HTML output pytest pytest-cov diff --git a/tests/conftest.py b/tests/conftest.py index 62c0662..c504c48 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,11 +1,28 @@ -# cspell:ignore rootdir +import sys + import pytest -from sphinx.testing.path import path + +if sys.version_info < (3, 8): + from importlib_metadata import version +else: + from importlib.metadata import version pytest_plugins = "sphinx.testing.fixtures" collect_ignore = ["roots"] -@pytest.fixture(scope="session") -def rootdir() -> path: - return path(__file__).parent.abspath() / "roots" +# cspell:ignore rootdir +sphinx_version = version("Sphinx") +if sphinx_version < "7.2": + from sphinx.testing.path import path + + @pytest.fixture(scope="session") + def rootdir() -> path: + return path(__file__).parent.abspath() / "roots" + +else: + from pathlib import Path + + @pytest.fixture(scope="session") + def rootdir() -> Path: + return Path(__file__).parent.absolute() / "roots"