Repository navigation
Expand file tree
/
Copy pathconftest.py
More file actions
55 lines (45 loc) · 1.8 KB
/
Copy pathconftest.py
File metadata and controls
55 lines (45 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Root pytest configuration and doctest namespace setup for libvt."""
from __future__ import annotations
import importlib.util
import pathlib
import typing as t
import pytest
import libvt
from libvt.style import AnsiColor
from libvt.testing import assert_screen, assert_screen_box
if t.TYPE_CHECKING:
from libvt.parser import Parser
from libvt.pytest_plugin import TerminalFactory
from libvt.terminal import FlightRecorder, Terminal
@pytest.fixture(autouse=True)
def _seed_doctest_namespace(
request: pytest.FixtureRequest,
doctest_namespace: dict[str, t.Any],
vt_recorder: FlightRecorder,
vt_terminal: Terminal,
vt_factory: TerminalFactory,
vt_parser: Parser,
) -> None:
"""Populate doctest globals with common ``libvt`` entry points and fixtures."""
doctest_namespace["libvt"] = libvt
doctest_namespace["Terminal"] = libvt.Terminal
doctest_namespace["AnsiColor"] = AnsiColor
doctest_namespace["assert_screen"] = assert_screen
doctest_namespace["assert_screen_box"] = assert_screen_box
doctest_namespace["vt_recorder"] = vt_recorder
doctest_namespace["vt_terminal"] = vt_terminal
doctest_namespace["vt_factory"] = vt_factory
doctest_namespace["vt_parser"] = vt_parser
if importlib.util.find_spec(
"syrupy"
) is not None and request.config.pluginmanager.hasplugin("syrupy"):
doctest_namespace["vt_snapshot"] = request.getfixturevalue("vt_snapshot")
def pytest_collect_file(
file_path: pathlib.Path,
parent: pytest.Collector,
) -> pytest.Collector | None:
"""Collect plain Python, console, and literalinclude blocks from Markdown docs."""
if file_path.suffix.lower() != ".md":
return None
from tests._docs_codeblocks import collect_markdown_codeblocks
return collect_markdown_codeblocks(file_path, parent)