Repository navigation
Description
Summary
libvt.pytest_plugin (libvt[pytest]) ships pure libvt fixtures (vt_recorder, vt_terminal, vt_factory, vt_parser, and vt_pty) with zero third-party snapshot-tool dependencies, while callers adopting VtSnapshotExtension from libvt.contrib.syrupy (libvt[syrupy]) want assert vt_screen(term) == vt_snapshot without repeating snapshot.use_extension(...) boilerplate in every conftest.py. Moving tool-agnostic VT serialization (serialize_vt_snapshot(), vt_screen(), format_vt_diff_lines()) into libvt.testing and registering vt_snapshot conditionally from libvt.contrib.syrupy (libvt_syrupy = "libvt.contrib.syrupy:_pytest_plugin") keeps libvt.pytest_plugin completely free of syrupy coupling while making vt_snapshot automatic when syrupy is active and invisible in pytest --fixtures when syrupy is uninstalled or disabled (-p no:syrupy).
Motivation
- Keep
libvt.pytest_plugintool-agnostic: Every fixture insrc/libvt/pytest_plugin.pyserveslibvtitself (Terminal,FlightRecorder,Parser,open_pty()). Placing asyrupy-specificSnapshotAssertionfixture insidelibvt.pytest_pluginleakssyrupytypes into the core plugin and advertisesvt_snapshotinpytest --fixtureseven in projects that useinline-snapshot,pytest-regressions, or plainassert_screen_box(). - Decouple serialization from
.ambrstorage:vt_screen(),serialize_vt_snapshot(), andformat_vt_diff_lines()use zerosyrupyAPIs; hosting them inlibvt.testinglets any test runner serialize and diff styled terminal screens without installingsyrupy. - Preserve failure diffs past
syrupypost-assert resets: Insyrupyv7.0.3, passingextension_classper assertion (assert term == snapshot(extension_class=VtSnapshotExtension)) queuessetattrcallbacks inSnapshotAssertion._post_assert_actions(src/syrupy/assertion.py) that reset_extensionback toAmberSnapshotExtensionduring_post_assert(), beforepytest_assertrepr_comparecallsget_assert_diff()andself.extension.diff_snapshots(). Bindingsnapshot.use_extension(get_vt_snapshot_extension())insidevt_snapshotpreserves customdiff_snapshots()output acrosslibvt, libtmux, and tmuxp without per-repositoryconftest.pyduplication or duplicatepytest11fixture collisions.
Proposal
- Move tool-agnostic serialization, scrubbing, and diffing to
src/libvt/testing.py:- Export
ScrubberSpec,VtTarget,VtScreenView,vt_screen(),serialize_vt_snapshot(), andformat_vt_diff_lines()fromlibvt.testingwith zeropytestorsyrupycoupling, while limitinglibvt.contrib.syrupy.__all__strictly toVtSnapshotExtension,get_vt_snapshot_extension, andvt_snapshot.
- Export
- Keep
src/libvt/pytest_plugin.py100%syrupy-free:- Document
vt_terminal,vt_factory,vt_recorder,vt_parser, andvt_ptywithReturnsand runnableExamplesdocstrings andautofixturereference cards indocs/api/pytest_plugin.md, with zerosyrupyimports orvt_snapshotregistration inlibvt.pytest_plugin.
- Document
- Register
vt_snapshotconditionally fromsrc/libvt/contrib/syrupy.py:- Add
libvt_syrupy = "libvt.contrib.syrupy:_pytest_plugin"under[project.entry-points.pytest11]inpyproject.toml. - In
_SyrupyPytestPlugin.pytest_configure(config), registervt_snapshotonly whenimportlib.util.find_spec("syrupy") is not None and config.pluginmanager.hasplugin("syrupy")is true, keepingimport libvt.contrib.syrupycold (libvt.terminal,libvt.testing,libvt._ucd,syrupy, andpytestunloaded at import time) and omittingvt_snapshotfrompytest --fixtureswheneversyrupyis absent or disabled via-p no:syrupy.
- Add
Alternatives
Keeping vt_snapshot inside src/libvt/pytest_plugin.py was rejected because it couples libvt[pytest] to a specific third-party snapshot tool and lists vt_snapshot in pytest --fixtures for non-syrupy test suites. Requiring callers to pass snapshot(extension_class=VtSnapshotExtension) inline was rejected because _post_assert_actions resets _extension prior to diff_snapshots(). Registering a second vt_snapshot pytest11 fixture inside libtmux.pytest_plugin was rejected because libtmux[vt] already installs libvt's pytest11 entry points.
References
- Companion serializer and
.ambrextension in Add boxed VT + SGR snapshot serialization in libvt.testing and syrupy adapter #64 and contrib(feat[syrupy]): Add VT snapshot extension #66 - Existing
vt_*fixtures insrc/libvt/pytest_plugin.py(v0.0.1a3) SnapshotAssertion_post_assert_actionsreset beforediff_snapshots()insrc/syrupy/assertion.py(v7.0.3)FixtureManager.parsefactories()plugin scanning insrc/_pytest/fixtures.py(9.2.0)- Downstream
libtmux[vt]integration in libtmux#933, libtmux#934, and libtmux#937
Activity
pytest_plugin(feat[syrupy]): Add vt_snapshot
pytest_plugin(feat[syrupy]): Add vt_snapshot
pytest_plugin(feat[syrupy]): Add vt_snapshot
pytest_plugin(feat[syrupy]): Add vt_snapshot
pytest_plugin(feat[syrupy]): Add vt_snapshot
pytest_plugin(feat[syrupy]): Add vt_snapshot
testing(feat): Decouple testing, plugin, syrupy
[-]Add `vt_snapshot` fixture to `libvt.pytest_plugin` for `syrupy`[/-][+]Decouple libvt.testing, libvt.pytest_plugin, and conditional syrupy hook[/+]testing(feat): Decouple testing, plugin, syrupy
testing(feat): Decouple testing, plugin, syrupy (#67)