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_terminal when a standard 24x80 terminal with an attached FlightRecorder fits the test.

  • Request vt_factory when the test chooses custom (rows, cols), scrollback limits, or terminal profiles.

  • Request vt_recorder when sharing or inspecting the 4 KiB FlightRecorder directly.

  • Request vt_parser when testing low-level VT500 byte parsing without a screen grid.

  • Request vt_pty when spawning an interactive subprocess on a POSIX pseudo-terminal (automatically skips on Windows).

Fixture summary

Fixture

Scope

Provides

vt_terminal

function

24x80 Terminal wired to vt_recorder

vt_factory

function

TerminalFactory for custom geometry or profiles

vt_recorder

function

4 KiB FlightRecorder ring buffer

vt_parser

function

Streaming Parser

vt_pty

function

POSIX PtyFactory (win32 skip)

Terminal fixtures

fixture libvt.pytest_plugin.vt_terminal → Terminal
fixture[source]
fixture[source]
fixture libvt.pytest_plugin.vt_terminal → Terminal

Return a fresh 24x80 Terminal with recorder.

Depends on:

vt_recorder, request

Returns:

Function-scoped 24x80 terminal pre-wired to vt_recorder() so failed assert_screen() checks include disassembled VT traces.

Examples

>>> vt_terminal.feed(b"\x1b[1;32mready\x1b[0m\r\ndone")
>>> vt_terminal.lines[:2]
('ready', 'done')
fixture libvt.pytest_plugin.vt_factory → TerminalFactory
fixture[source]
fixture[source]
fixture libvt.pytest_plugin.vt_factory → TerminalFactory

Return a typed factory creating Terminal instances.

Depends on:

request

Returns:

Keyword-configurable constructor accepting rows, cols, scrollback, profile, policy, limits, on_event, encoding, record_events, and recorder.

Examples

>>> term = vt_factory(rows=2, cols=12)
>>> term.feed(b"step 1\r\nstep 2")
>>> term.lines
('step 1', 'step 2')
fixture libvt.pytest_plugin.vt_recorder → FlightRecorder
fixture[source]
fixture[source]
fixture libvt.pytest_plugin.vt_recorder → FlightRecorder

Return a fresh 4 KiB FlightRecorder.

Returns:

Per-test ring buffer capturing up to 4096 input bytes for ScreenAssertionError failure traces.

Used by:

vt_terminal

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

fixture libvt.pytest_plugin.vt_parser → Parser
fixture[source]
fixture[source]
fixture libvt.pytest_plugin.vt_parser → Parser

Return a fresh streaming Parser.

Returns:

Function-scoped VT500 byte parser in GROUND state.

Examples

>>> actions = vt_parser.feed(b"\x1b[31mok")
>>> [type(a).__name__ for a in actions]
['CsiDispatch', 'Print']
fixture libvt.pytest_plugin.vt_pty → PtyFactory
fixture[source]
fixture[source]
fixture libvt.pytest_plugin.vt_pty → PtyFactory

Return a POSIX open_pty() factory (skips on Windows).

Depends on:

request

Returns:

Async context-manager factory spawning subprocesses attached to a POSIX pseudo-terminal. Calls pytest.skip on win32.

Factory protocols

class libvt.pytest_plugin.TerminalFactory
class libvt.pytest_plugin.TerminalFactory

Bases: Protocol

Typed callable protocol returned by the vt_factory() fixture.

class libvt.pytest_plugin.PtyFactory
class libvt.pytest_plugin.PtyFactory

Bases: Protocol

Typed async context-manager factory returned by vt_pty().