Snapshot testing for Textual apps
Project description
pytest-textual-snapshot
Snapshot testing for Textual apps.
Installation
Install using pip
:
pip install pytest-textual-snapshot
After installing, the snap_compare
fixture will automatically be made available.
About
A pytest-textual-snapshot
test saves an SVG screenshot of a running Textual app to disk.
The next time the test runs, it takes another screenshot and compares it to the saved one.
If the new screenshot differs from the old one, the test fails.
This is a convenient way to quickly and automatically detect visual regressions in your applications.
Usage
Running tests
You can run your tests using pytest
as normal.
My snapshot test failed, what do I do?
If your snapshot test fails, it means that the screenshot taken during the test session differs from the last screenshot taken. This change is shown in the failure report, which you'll be given a linked to in the event of a failure.
If the diff shown in the failure report looks correct, you can update the snapshot on disk
by running pytest
with the --snapshot-update
flag.
Writing tests
Basic usage
Inject the snap_compare
fixture into your test and call
it with the path to the Textual app (the file containing the App
subclass).
def test_something(snap_compare):
assert snap_compare("path/to/app.py")
Pressing keys
Key presses can be simulated before the screenshot is taken.
def test_something(snap_compare):
assert snap_compare("path/to/app.py", press=["tab", "left", "a"])
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytest_textual_snapshot-0.4.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63782e053928a925d88ff7359dd640f2900e23bc708b3007f8b388e65f2527cb |
|
MD5 | 5842a00bf14bf764dbc309b8fe6eddf5 |
|
BLAKE2b-256 | f7cf582c7e2dcbc2947dc68252821578404a0c5ec2ff6e5aa91a3ddc0e4bfbab |
Hashes for pytest_textual_snapshot-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 879cc5de29cdd31cfe1b6daeb1dc5e42682abebcf4f88e7e3375bd5200683fc0 |
|
MD5 | f781cc55a8a6133e87bfef75019fe736 |
|
BLAKE2b-256 | 638b445c871e8dc096419e756bb3d34de9e074d302278f7e584d1bd8f0e4a0ef |