### Install pytest-textual-snapshot Source: https://github.com/textualize/pytest-textual-snapshot/blob/main/README.md Installs the `pytest-textual-snapshot` plugin using pip. After installation, the `snap_compare` fixture is automatically available for use in pytest tests. ```bash pip install pytest-textual-snapshot ``` -------------------------------- ### Basic Snapshot Test with App Path Source: https://github.com/textualize/pytest-textual-snapshot/blob/main/README.md Shows how to perform a snapshot test by providing the file path to a Textual application. The plugin will load and run the app from the specified path for comparison. ```python def test_something(snap_compare): assert snap_compare("path/to/app.py") ``` -------------------------------- ### Snapshot Test with Simulated Key Presses Source: https://github.com/textualize/pytest-textual-snapshot/blob/main/README.md Illustrates how to simulate key presses before a screenshot is captured. The `press` parameter accepts a list of keys to simulate, allowing for testing interactive elements. ```python def test_something(snap_compare): assert snap_compare("path/to/app.py", press=["tab", "left", "a"]) ``` -------------------------------- ### Basic Snapshot Test with App Instance Source: https://github.com/textualize/pytest-textual-snapshot/blob/main/README.md Demonstrates a basic snapshot test by injecting the `snap_compare` fixture and passing a non-running Textual `App` instance to it. Asserts that the screenshot comparison passes. ```python def test_my_app(snap_compare): app = MyTextualApp() # a *non-running* Textual `App` instance assert snap_compare(app) ``` -------------------------------- ### Snapshot Test with Custom Pre-Screenshot Code Source: https://github.com/textualize/pytest-textual-snapshot/blob/main/README.md Enables running custom asynchronous code before the screenshot is taken using the `run_before` parameter. This is useful for setting up specific states or performing actions within the Textual app's pilot. ```python def test_something(snap_compare): async def run_before(pilot: Pilot): await pilot.press("ctrl+p") # You can run arbitrary code before the screenshot occurs: await disable_blink_for_active_cursors(pilot) await pilot.press(*"view") assert snap_compare(MyApp(), run_before=run_before) ``` -------------------------------- ### Snapshot Test with Customized Terminal Size Source: https://github.com/textualize/pytest-textual-snapshot/blob/main/README.md Allows customization of the terminal size used during the snapshot capture via the `terminal_size` parameter. This is helpful for testing layout responsiveness or ensuring content fits within specific dimensions. ```python def test_another_thing(snap_compare): assert snap_compare(MyApp(), terminal_size=(80, 34)) ``` -------------------------------- ### Updating Snapshots Source: https://github.com/textualize/pytest-textual-snapshot/blob/main/README.md Updates the saved snapshot files when differences are detected. Run pytest with the `--snapshot-update` flag to regenerate the baseline screenshots if the changes are intentional. ```bash pytest --snapshot-update ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.