diff --git a/tests/conftest.py b/tests/conftest.py index f0ca478ba1..b884f132f7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,18 +14,14 @@ import sphinx import sphinx.locale from sphinx.testing.util import _clean_up_global_state +from tests.utils import TEST_ROOTS_DIR + if TYPE_CHECKING: from collections.abc import Callable, Iterator from typing import Any from sphinx.testing.util import SphinxTestApp -_TESTS_ROOT = Path(__file__).resolve().parent -if 'CI' in os.environ and (_TESTS_ROOT / 'roots-read-only').is_dir(): - _ROOTS_DIR = _TESTS_ROOT / 'roots-read-only' -else: - _ROOTS_DIR = _TESTS_ROOT / 'roots' - def _init_console( locale_dir: str | os.PathLike[str] | None = sphinx.locale._LOCALE_DIR, @@ -45,14 +41,14 @@ sphinx.locale.init_console = _init_console pytest_plugins = ['sphinx.testing.fixtures'] # Exclude 'roots' dirs for pytest test collector -collect_ignore = ['roots'] +collect_ignore = ['roots', 'roots-read-only'] os.environ['SPHINX_AUTODOC_RELOAD_MODULES'] = '1' @pytest.fixture(scope='session') def rootdir() -> Path: - return _ROOTS_DIR + return TEST_ROOTS_DIR def pytest_report_header(config: pytest.Config) -> str: @@ -61,7 +57,7 @@ def pytest_report_header(config: pytest.Config) -> str: ] if sys.version_info[:2] >= (3, 13): lines.append(f'GIL enabled?: {sys._is_gil_enabled()}') - lines.append(f'test roots directory: {_ROOTS_DIR}') + lines.append(f'test roots directory: {TEST_ROOTS_DIR}') if hasattr(config, '_tmp_path_factory'): lines.append(f'base tmp_path: {config._tmp_path_factory.getbasetemp()}') return '\n'.join(lines) diff --git a/tests/test_util/test_util_logging.py b/tests/test_util/test_util_logging.py index c21434a841..2eee35ce84 100644 --- a/tests/test_util/test_util_logging.py +++ b/tests/test_util/test_util_logging.py @@ -18,7 +18,7 @@ from sphinx.util.console import colorize from sphinx.util.logging import is_suppressed_warning, prefixed_warnings from sphinx.util.parallel import ParallelTasks -from tests.utils import TESTS_ROOT +from tests.utils import TEST_ROOTS_DIR if TYPE_CHECKING: from sphinx.testing.util import SphinxTestApp @@ -297,7 +297,7 @@ def force_colors(): def test_log_no_ansi_colors(tmp_path): with force_colors(): wfile = tmp_path / 'warnings.txt' - srcdir = TESTS_ROOT / 'roots' / 'test-nitpicky-warnings' + srcdir = TEST_ROOTS_DIR / 'test-nitpicky-warnings' argv = list(map(str, ['-b', 'html', srcdir, tmp_path, '-n', '-w', wfile])) retcode = build_main(argv) assert retcode == 0 diff --git a/tests/utils.py b/tests/utils.py index 59757edbd9..b75f9cc1c4 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -2,6 +2,7 @@ from __future__ import annotations __all__ = ('http_server',) +import os import socket from contextlib import contextmanager from http.server import ThreadingHTTPServer @@ -19,10 +20,16 @@ if TYPE_CHECKING: from sphinx.application import Sphinx +TESTS_ROOT: Final[Path] = Path(__file__).resolve().parent +TEST_ROOTS_DIR: Final[Path] = TESTS_ROOT / ( + 'roots-read-only' + if 'CI' in os.environ and (TESTS_ROOT / 'roots-read-only').is_dir() + else 'roots' +) + # Generated with: # $ openssl req -new -x509 -days 3650 -nodes -out cert.pem \ # -keyout cert.pem -addext "subjectAltName = DNS:localhost" -TESTS_ROOT: Final[Path] = Path(__file__).resolve().parent CERT_FILE: Final[str] = str(TESTS_ROOT / 'certs' / 'cert.pem')