Debian Codegraph @

tests/test_builders/conftest.py

raw
1 from __future__ import annotations
2
3 from typing import TYPE_CHECKING
4
5 import pytest
6
7 from sphinx.testing.util import etree_parse
8
9 if TYPE_CHECKING:
10 from collections.abc import Callable, Iterator
11 from pathlib import Path
12 from xml.etree.ElementTree import ElementTree
13
14 _etree_cache: dict[Path, ElementTree] = {}
15
16
17 def _parse(path: Path) -> ElementTree:
18 if path in _etree_cache:
19 return _etree_cache[path]
20
21 _etree_cache[path] = tree = etree_parse(path)
22 return tree
23
24
25 @pytest.fixture(scope='package')
26 def cached_etree_parse() -> Iterator[Callable[[Path], ElementTree]]:
27 yield _parse
28 _etree_cache.clear()