Textualize / pytest-textual-snapshot

Snapshot testing for Textual applications
MIT License
21 stars 4 forks source link

Feature request: allow passing an `App` to `snap_compare` #8

Closed godlygeek closed 1 month ago

godlygeek commented 11 months ago

Currently snap_compare requires the path to a file that it will import and run, but that's got poor ergonomics for tests that want to dependency inject mocked data into the app, as well as for Textual apps that aren't typically run directly by the user as a script.

In my case, I'd like to use this library for testing the Memray TUI, which I'm currently working on moving to Textual from Rich. That TUI is run as a subcommand of the memray CLI (e.g. memray live ... or memray run --live ...), so there is no file with a global App instance to be run. I can create one, just for testing, but even then I have no easy way to pass the mock data that I want the tests to work with from my test module into that new file. It seems like allowing an App instance to be passed to snap_compare instead of a path to a file would require less work from me, and make it easier for the test to supply mock data to the app.

darrenburns commented 1 month ago

Hey, I forgot to update this issue but this is now possible as of 1.0.0!

1.0.0 also produces separate SVG files per snapshot test (meaning you'll have to regenerate them), but this means you can easily view snapshots and even view them directly inside GitHub PRs!