Skip to content

Commit f47da1d

Browse files
committed
docs(replay): Share a runnable failing test
why: Readers need a failure that generates an artifact on first use. what: - Run the same example from the guide and the replay regression. - Show where the written trailing space appears in the saved screen.
1 parent 4fe45c5 commit f47da1d

4 files changed

Lines changed: 31 additions & 14 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ styles:
134134

135135
[`libvt.pytest_plugin`][pytest_plugin] (`libvt[pytest]`) provides `vt_terminal`
136136
(wired to a 4 KiB `FlightRecorder`), `vt_factory`, `vt_recorder`, `vt_parser`,
137-
and POSIX `vt_pty` fixtures with no snapshot-tool dependencies:
137+
and POSIX `vt_pty` fixtures with no snapshot-tool dependencies.
138138

139139
Use `--vt-replay-dir` to [replay a failed terminal test][pytest_replay]
140140
from the bytes and resizes saved by pytest.

‎docs/topics/testing.md‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,19 @@ with no dependency on `syrupy` or any other snapshot tool:
217217

218218
Pass `--vt-replay-dir` to capture failures from tests using
219219
{fixture}`vt_terminal`, {fixture}`vt_factory`, or POSIX {fixture}`vt_pty`.
220+
The {download}`example <../../examples/replay_prompt.py>` draws `X` while
221+
the screen is four columns wide. After widening the screen, it writes a
222+
space in column 4. The assertion deliberately omits that space.
223+
224+
```{literalinclude} ../../examples/replay_prompt.py
225+
:language: python
226+
:start-at: from libvt.pytest_plugin
227+
```
228+
229+
Run the failing test from the repository root to save the trace.
220230

221231
```console
222-
$ pytest --vt-replay-dir=.vt-replays
232+
$ uv run pytest -q examples/replay_prompt.py --vt-replay-dir=.vt-replays
223233
```
224234

225235
Run `python -m libvt replay` with the JSON path printed in the test report.

‎examples/replay_prompt.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""A deliberately failing screen assertion for the pytest replay guide."""
2+
3+
from __future__ import annotations
4+
5+
from libvt.pytest_plugin import TerminalFactory
6+
from libvt.testing import assert_screen
7+
8+
9+
def test_prompt(vt_factory: TerminalFactory) -> None:
10+
"""Draw while the terminal is narrow and leave a written space after X."""
11+
term = vt_factory(rows=2, cols=8)
12+
term.resize(rows=2, cols=4, reflow=False)
13+
term.feed(b"\x1b[1;7")
14+
term.feed(b"HX")
15+
term.resize(rows=2, cols=8, reflow=False)
16+
term.feed(b"\x1b[1;5H ")
17+
assert_screen(term, [" X"])

‎tests/test_testing.py‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -435,18 +435,8 @@ def test_pytest_failure_replays_ordered_resize_and_written_space(
435435
) -> None:
436436
"""Replay a failing assertion from outside the original working directory."""
437437
script = tmp_path / "test_example.py"
438-
script.write_text(
439-
"from libvt.testing import assert_screen\n"
440-
"def test_capture(vt_factory):\n"
441-
" term = vt_factory(rows=2, cols=8)\n"
442-
" term.resize(rows=2, cols=4, reflow=False)\n"
443-
" term.feed(b'\\x1b[1;7')\n"
444-
" term.feed(b'HX')\n"
445-
" term.resize(rows=2, cols=8, reflow=False)\n"
446-
" term.feed(b'\\x1b[1;5H ')\n"
447-
" assert_screen(term, [' X'])\n",
448-
encoding="utf-8",
449-
)
438+
example = pathlib.Path(__file__).resolve().parents[1] / "examples/replay_prompt.py"
439+
shutil.copyfile(example, script)
450440
outdir = tmp_path / "artifacts"
451441
config = tmp_path / "pytest.ini"
452442
config.write_text("[pytest]\n", encoding="utf-8")

0 commit comments

Comments
 (0)