Debian Codegraph @

core/tests/conftest.py

raw symbols SCIP
1 """Fixtures for tests."""
2
3 from __future__ import annotations
4
5 import pathlib
6 import typing as t
7
8 import pytest
9
10 from rstcheck_core import _extras
11
12 REPO_DIR = pathlib.Path(__file__).resolve().parents[1].resolve()
13 TESTING_DIR = REPO_DIR / "testing"
14 EXAMPLES_DIR = TESTING_DIR / "examples"
15
16
17 @pytest.fixture(name="patch_docutils_directives_and_roles_dict")
18 def _patch_docutils_directives_and_roles_dict_fixture(monkeypatch: pytest.MonkeyPatch) -> None:
19 """Monkeypatch docutils' directives and roles state dicts.
20
21 This patch is required when tests are run in parallel (default), because they would
22 under the hood all write to the same state dicts otherwise and influence each other.
23 """
24 test_dict_directives: dict[str, t.Any] = {}
25 test_dict_roles: dict[str, t.Any] = {}
26
27 if _extras.SPHINX_INSTALLED:
28 monkeypatch.setattr("sphinx.util.docutils.directives._directives", test_dict_directives)
29 monkeypatch.setattr("sphinx.util.docutils.roles._roles", test_dict_roles)
30 else:
31 monkeypatch.setattr("docutils.parsers.rst.directives._directives", test_dict_directives)
32 monkeypatch.setattr("docutils.parsers.rst.roles._roles", test_dict_roles)