From 29da6badfda9faa9a62773dcc3fa1fa1e7003922 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Tue, 20 Sep 2022 15:29:42 +0100 Subject: [PATCH] Use type hints and add docstring to snap_compare --- tests/snapshot_tests/conftest.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/snapshot_tests/conftest.py b/tests/snapshot_tests/conftest.py index c9e7c86eb..d2508d046 100644 --- a/tests/snapshot_tests/conftest.py +++ b/tests/snapshot_tests/conftest.py @@ -15,6 +15,7 @@ from _pytest.terminal import TerminalReporter from jinja2 import Template from rich.console import Console from rich.panel import Panel +from syrupy import SnapshotAssertion from textual._doc import take_svg_screenshot @@ -24,8 +25,13 @@ snapshot_pass = pytest.StashKey[bool]() @pytest.fixture -def snap_compare(snapshot, request: FixtureRequest) -> Callable[[str], bool]: - def compare(app_path: str, snapshot) -> bool: +def snap_compare(snapshot: SnapshotAssertion, request: FixtureRequest) -> Callable[[str], bool]: + """ + This fixture returns a function which can be used to compare the output of a Textual + app with the output of the same app in the past. This is snapshot testing, and it + used to catch regressions in output. + """ + def compare(app_path: str, snapshot: SnapshotAssertion) -> bool: node = request.node actual_screenshot = take_svg_screenshot(app_path) result = snapshot == actual_screenshot