Skip to content

API turboframe.testing.terminal

rafageist edited this page Dec 4, 2026 · 4 revisions

turboframe.testing.terminal

Source: turboframe/testing/terminal.py. Generated from the code of TurboFrame 0.3.0 by tools/wiki_api.py.

Acceptance tests in a real terminal: a pytest plugin.

An application's acceptance/conftest.py says:

pytest_plugins = ["turboframe.testing.terminal"]

and its pyproject.toml names its variables' prefix (MYAPP gives MYAPP_ACCEPTANCE_RUN, MYAPP_ACCEPTANCE_ARTIFACTS...):

[tool.pytest.ini_options]
turboframe_acceptance_prefix = "MYAPP"

It needs tui-test and psutil (pip install "turboframe[terminal]").

Fixtures, in the order a test asks for them:

  • evidence: a folder for what explains a failure, copied to $<PREFIX>_ACCEPTANCE_ARTIFACTS/<test>/ only when the test failed;
  • checkpoint: the scenario's screens at its meaningful moments (Checkpoints), kept in $<PREFIX>_ACCEPTANCE_CHECKPOINTS/<test>/;
  • box: a Sandbox, the project folder and settings of this test only, whose run_id marks every process the test starts;
  • no_process_left: fails the test when a marked process outlives it (and kills it); ask for it before terminal;
  • terminal: a tui-test terminal; on a failure its trace and screen go to the evidence.

need(ok, reason) skips a test whose tool is missing, and fails it in CI ($<PREFIX>_ACCEPTANCE_STRICT=1). start, alt and exit_code drive the terminal; marked, left_behind, describe and kill find a test's processes; screen(app) is a Pilot-driven app's screen as text.

Contents

COLS, ROWS, Checkpoints, Sandbox, alt, describe, details, exit_code, kill, left_behind, marked, need, sandbox, screen, start, wait_none_left

COLS

120

ROWS

34

class Checkpoints

class Checkpoints
Checkpoints(folder: Path, test: str)

Screens of a scenario at its meaningful moments, kept whether it passes or fails: each as SVG (what a terminal shows) and as text, and a line of checkpoints.json with its order, name and caption. A checkpoint never waits or checks anything itself: it records the screen the scenario's own wait reached.

  • pilot(app, name: str, caption: str) -> None: The screen of an application driven by Pilot (in the test's process).
  • async terminal(tt, name: str, caption: str) -> None: The screen of the application in a real terminal (tui-test).

class Sandbox

class Sandbox
Sandbox(root: Path, home: Path, run_id: str, mark: str, extra: dict = <factory>)

The project a test opens and the settings of this test only. mark, set to run_id, is inherited by every process the test starts, and every process those start.

  • env(base: dict | None = None) -> dict
  • apply(monkeypatch) -> None: The same, for an application that runs in the test's own process (Pilot).

alt

async def alt(tt, key: str) -> None

Alt+key as one write, as a terminal sends it (tui-test's press("Alt+x") arrives as Esc, then x).

describe

def describe(procs: list) -> str

details

def details(procs: list) -> str

Each process as the evidence keeps it: pid, parent, state, start, folder and command line.

exit_code

async def exit_code(tt) -> int | None

The program's own exit code (tui-test's get_exit_code is a shell command's).

kill

def kill(procs: list) -> None

Cleanup after a failed check, so one test's leftovers never reach the next.

left_behind

def left_behind(mark: str, run_id: str, evidence: Path, timeout: float) -> list

The marked processes still alive after timeout seconds; when there are any, what is known of each is written to evidence/processes.txt before anything kills them.

marked

def marked(mark: str, run_id: str) -> list

The processes whose environment has mark=run_id, except this one (a Pilot journey runs the application in the test's process).

need

def need(ok: bool, reason: str) -> None

A scenario's precondition on the machine: skipped locally without it, failed in CI ($<PREFIX>_ACCEPTANCE_STRICT=1), so a missing tool never passes as a skipped test.

sandbox

def sandbox(tmp_path: Path, mark: str, name: str = 'project') -> Sandbox

screen

def screen(app) -> str

The screen of an application driven by Pilot, as text: the lines Textual draws.

start

async def start(tt, command: str | list[str], box: Sandbox, *args: str, cols: int = 120, rows: int = 34) -> None

Start command (a program, or a program and its first arguments) and args in the terminal, in the box's project, with its settings and mark.

wait_none_left

def wait_none_left(mark: str, run_id: str, timeout: float) -> list

The marked processes still alive after timeout seconds (none: an empty list): the condition, polled until it holds or the deadline passes.

Clone this wiki locally