sphinx/tests/test_builders/conftest.py
Bénédikt Tran 885818bb7f
[tests] move utilities and static data into dedicated modules and remove `html5lib` (#12173)
Since #12168, HTML files are now XML compliant, hence ``html5lib`` is no more needed as a testing dependencies.
2024-03-25 11:03:44 +01:00

29 lines
653 B
Python

from __future__ import annotations
from typing import TYPE_CHECKING
import pytest
from sphinx.testing.util import etree_parse
if TYPE_CHECKING:
from collections.abc import Callable, Generator
from pathlib import Path
from xml.etree.ElementTree import ElementTree
_etree_cache: dict[Path, ElementTree] = {}
def _parse(path: Path) -> ElementTree:
if path in _etree_cache:
return _etree_cache[path]
_etree_cache[path] = tree = etree_parse(path)
return tree
@pytest.fixture(scope='package')
def cached_etree_parse() -> Generator[Callable[[Path], ElementTree], None, None]:
yield _parse
_etree_cache.clear()