From 4bbbc93952e0d6726c67e8a3e9163cc89cbcafe1 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 21 May 2024 23:08:55 -0400 Subject: [PATCH] tests: fix varioun versions of sphinx (#46) Signed-off-by: Henry Schreiner --- noxfile.py | 3 +-- pyproject.toml | 6 +++++- tests/conftest.py | 24 ++++++++++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/noxfile.py b/noxfile.py index 1361f61..d20a802 100644 --- a/noxfile.py +++ b/noxfile.py @@ -62,6 +62,5 @@ def tests(session): """ Run the unit and regular tests. """ - # Setuptools is required due to sphinx installing sphinxcontrib extensions that use pkg_resources (fixed upstream but not released yet) - session.install(".", "pytest", "setuptools") + session.install(".[test]", silent=False) session.run("pytest", *session.posargs) diff --git a/pyproject.toml b/pyproject.toml index 6fbdac9..51bbf48 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,11 @@ dynamic = ["version"] Homepage = "https://github.com/scikit-build/moderncmakedomain" [project.optional-dependencies] -test = ["pytest"] +test = [ + # Setuptools is required due to sphinx installing sphinxcontrib extensions that use pkg_resources (fixed upstream but not released yet) + "pytest", + "defusedxml", +] [tool.pytest.ini_options] minversion = "6.0" diff --git a/tests/conftest.py b/tests/conftest.py index c62ee4e..edd20d0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,25 @@ import pytest -from pathlib import Path +import sys + +if sys.version_info < (3, 8): + from importlib_metadata import version +else: + from importlib.metadata import version + +sphinx_vesion = tuple(int(d) for d in version("sphinx").split(".")[:2]) pytest_plugins = 'sphinx.testing.fixtures' -@pytest.fixture(scope="session") -def rootdir(): - return Path(__file__).parent.absolute() / "roots" +if sphinx_vesion < (7, 3): + from sphinx.testing.path import path + + @pytest.fixture(scope="session") + def rootdir(): + return path(__file__).parent.abspath() / "roots" +else: + from pathlib import Path + + @pytest.fixture(scope="session") + def rootdir(): + return Path(__file__).parent.absolute() / "roots"