libvt.pytest_plugin¶
libvt registers an import-light pytest11 plugin providing vt_* terminal,
parser, recorder, and POSIX PTY fixtures when
pytest is installed:
$ uv add --dev "libvt[pytest]>=0.0.1a6,<0.1"
Quick start¶
Declare any vt_* fixture as a test parameter; pytest injects it
automatically. libvt’s own conftest.py also seeds these fixtures in
doctest_namespace so the examples below execute in CI:
>>> from libvt.pytest_plugin import TerminalFactory
>>> from libvt.testing import assert_screen_box
>>> def test_inline_status(vt_factory: TerminalFactory) -> None:
... term = vt_factory(rows=2, cols=10)
... term.feed(b"\x1b[1;32mOK\x1b[0m\r\nready")
... assert_screen_box(
... term,
... """
... ┌──────────┐
... │OK │
... │ready │
... └──────────┘
... """,
... cursor=(1, 5),
... )
>>> test_inline_status(vt_factory)
Which fixture to request¶
Request
vt_terminalwhen a standard24x80terminal with an attachedFlightRecorderfits the test.Request
vt_factorywhen the test chooses custom(rows, cols), scrollback limits, or terminal profiles.Request
vt_recorderwhen sharing or inspecting the 4 KiBFlightRecorderdirectly.Request
vt_parserwhen testing low-level VT500 byte parsing without a screen grid.Request
vt_ptywhen spawning an interactive subprocess on a POSIX pseudo-terminal (automatically skips on Windows).
Fixture summary¶
Fixture |
Scope |
Provides |
|---|---|---|
function |
|
|
function |
|
|
function |
4 KiB |
|
function |
Streaming |
|
function |
POSIX |
Terminal fixtures¶
Return a fresh
24x80Terminalwith recorder.- Depends on:
- Returns:
Function-scoped
24x80terminal pre-wired tovt_recorder()so failedassert_screen()checks include disassembled VT traces.
Examples
>>> vt_terminal.feed(b"\x1b[1;32mready\x1b[0m\r\ndone") >>> vt_terminal.lines[:2] ('ready', 'done')
Return a typed factory creating
Terminalinstances.- Depends on:
- Returns:
Keyword-configurable constructor accepting
rows,cols,scrollback,profile,policy,limits,on_event,encoding,record_events, andrecorder.
Examples
>>> term = vt_factory(rows=2, cols=12) >>> term.feed(b"step 1\r\nstep 2") >>> term.lines ('step 1', 'step 2')
Return a fresh 4 KiB
FlightRecorder.- Returns:
Per-test ring buffer capturing up to 4096 input bytes for
ScreenAssertionErrorfailure traces.- Used by:
Examples
>>> from libvt import Terminal >>> term = Terminal(rows=1, cols=10, recorder=vt_recorder) >>> term.feed(b"\x1b[31merr\x1b[0m") >>> vt_recorder.tail() b'\x1b[31merr\x1b[0m'
Parser & PTY fixtures¶
Return a fresh streaming
Parser.- Returns:
Function-scoped VT500 byte parser in
GROUNDstate.
Examples
>>> actions = vt_parser.feed(b"\x1b[31mok") >>> [type(a).__name__ for a in actions] ['CsiDispatch', 'Print']
Return a POSIX
open_pty()factory (skips on Windows).- Depends on:
- Returns:
Async context-manager factory spawning subprocesses attached to a POSIX pseudo-terminal. Calls
pytest.skiponwin32.
Factory protocols¶
-
class libvt.pytest_plugin.TerminalFactory¶class libvt.pytest_plugin.TerminalFactory¶
Bases:
ProtocolTyped callable protocol returned by the
vt_factory()fixture.