Skip to content

Commit fcc9ca0

Browse files
authored
Define and use TEST_ROOTS_DIR (#14020)
1 parent 8c86bad commit fcc9ca0

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

tests/conftest.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@
1414
import sphinx.locale
1515
from sphinx.testing.util import _clean_up_global_state
1616

17+
from tests.utils import TEST_ROOTS_DIR
18+
1719
if TYPE_CHECKING:
1820
from collections.abc import Callable, Iterator
1921
from typing import Any
2022

2123
from sphinx.testing.util import SphinxTestApp
2224

23-
_TESTS_ROOT = Path(__file__).resolve().parent
24-
if 'CI' in os.environ and (_TESTS_ROOT / 'roots-read-only').is_dir():
25-
_ROOTS_DIR = _TESTS_ROOT / 'roots-read-only'
26-
else:
27-
_ROOTS_DIR = _TESTS_ROOT / 'roots'
28-
2925

3026
def _init_console(
3127
locale_dir: str | os.PathLike[str] | None = sphinx.locale._LOCALE_DIR,
@@ -45,14 +41,14 @@ def _init_console(
4541
pytest_plugins = ['sphinx.testing.fixtures']
4642

4743
# Exclude 'roots' dirs for pytest test collector
48-
collect_ignore = ['roots']
44+
collect_ignore = ['roots', 'roots-read-only']
4945

5046
os.environ['SPHINX_AUTODOC_RELOAD_MODULES'] = '1'
5147

5248

5349
@pytest.fixture(scope='session')
5450
def rootdir() -> Path:
55-
return _ROOTS_DIR
51+
return TEST_ROOTS_DIR
5652

5753

5854
def pytest_report_header(config: pytest.Config) -> str:
@@ -61,7 +57,7 @@ def pytest_report_header(config: pytest.Config) -> str:
6157
]
6258
if sys.version_info[:2] >= (3, 13):
6359
lines.append(f'GIL enabled?: {sys._is_gil_enabled()}')
64-
lines.append(f'test roots directory: {_ROOTS_DIR}')
60+
lines.append(f'test roots directory: {TEST_ROOTS_DIR}')
6561
if hasattr(config, '_tmp_path_factory'):
6662
lines.append(f'base tmp_path: {config._tmp_path_factory.getbasetemp()}')
6763
return '\n'.join(lines)

tests/test_util/test_util_logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from sphinx.util.logging import is_suppressed_warning, prefixed_warnings
1919
from sphinx.util.parallel import ParallelTasks
2020

21-
from tests.utils import TESTS_ROOT
21+
from tests.utils import TEST_ROOTS_DIR
2222

2323
if TYPE_CHECKING:
2424
from sphinx.testing.util import SphinxTestApp
@@ -297,7 +297,7 @@ def force_colors():
297297
def test_log_no_ansi_colors(tmp_path):
298298
with force_colors():
299299
wfile = tmp_path / 'warnings.txt'
300-
srcdir = TESTS_ROOT / 'roots' / 'test-nitpicky-warnings'
300+
srcdir = TEST_ROOTS_DIR / 'test-nitpicky-warnings'
301301
argv = list(map(str, ['-b', 'html', srcdir, tmp_path, '-n', '-w', wfile]))
302302
retcode = build_main(argv)
303303
assert retcode == 0

tests/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
__all__ = ('http_server',)
44

5+
import os
56
import socket
67
from contextlib import contextmanager
78
from http.server import ThreadingHTTPServer
@@ -19,10 +20,16 @@
1920

2021
from sphinx.application import Sphinx
2122

23+
TESTS_ROOT: Final[Path] = Path(__file__).resolve().parent
24+
TEST_ROOTS_DIR: Final[Path] = TESTS_ROOT / (
25+
'roots-read-only'
26+
if 'CI' in os.environ and (TESTS_ROOT / 'roots-read-only').is_dir()
27+
else 'roots'
28+
)
29+
2230
# Generated with:
2331
# $ openssl req -new -x509 -days 3650 -nodes -out cert.pem \
2432
# -keyout cert.pem -addext "subjectAltName = DNS:localhost"
25-
TESTS_ROOT: Final[Path] = Path(__file__).resolve().parent
2633
CERT_FILE: Final[str] = str(TESTS_ROOT / 'certs' / 'cert.pem')
2734

2835

0 commit comments

Comments
 (0)