Skip to content

Commit 005ac20

Browse files
authored
Merge pull request Textualize#11 from Textualize/updates-july24
Various improvements
2 parents 7222778 + e4e247b commit 005ac20

File tree

5 files changed

+590
-91
lines changed

5 files changed

+590
-91
lines changed

README.md

+46-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# pytest-textual-snapshot
1+
# `pytest-textual-snapshot`
22

3-
Snapshot testing for Textual apps.
3+
A pytest plugin for snapshot testing Textual applications.
4+
5+
<img width="1325" alt="image" src="https://github.com/user-attachments/assets/a5079356-ef0f-4c7e-9ed2-bf2115e75c4f">
46

57
## Installation
68

@@ -23,7 +25,7 @@ This is a convenient way to quickly and automatically detect visual regressions
2325

2426
### Running tests
2527

26-
You can run your tests using `pytest` as normal.
28+
You can run your tests using `pytest` as normal. You can use `pytest-xdist` to run your tests in parallel.
2729

2830
#### My snapshot test failed, what do I do?
2931

@@ -39,7 +41,13 @@ by running `pytest` with the `--snapshot-update` flag.
3941
#### Basic usage
4042

4143
Inject the `snap_compare` fixture into your test and call
42-
it with the path to the Textual app (the file containing the `App` subclass).
44+
it with an app instance or the path to the Textual app (the file containing the `App` subclass).
45+
46+
```python
47+
def test_my_app(snap_compare):
48+
app = MyTextualApp() # a *non-running* Textual `App` instance
49+
assert snap_compare(app)
50+
```
4351

4452
```python
4553
def test_something(snap_compare):
@@ -54,3 +62,37 @@ Key presses can be simulated before the screenshot is taken.
5462
def test_something(snap_compare):
5563
assert snap_compare("path/to/app.py", press=["tab", "left", "a"])
5664
```
65+
66+
#### Run code before screenshot
67+
68+
You can run some code before capturing a screenshot using the `run_before` parameter.
69+
70+
```python
71+
def test_something(snap_compare):
72+
async def run_before(pilot: Pilot):
73+
await pilot.press("ctrl+p")
74+
# You can run arbitrary code before the screenshot occurs:
75+
await disable_blink_for_active_cursors(pilot)
76+
await pilot.press(*"view")
77+
78+
assert snap_compare(MyApp(), run_before=run_before)
79+
```
80+
81+
#### Customizing the size of the terminal
82+
83+
If you need to change the size of the terminal (for example to fit in more content or test layout-related code), you can adjust the `terminal_size` parameter.
84+
85+
```python
86+
def test_another_thing(snap_compare):
87+
assert snap_compare(MyApp(), terminal_size=(80, 34))
88+
```
89+
90+
#### Quickly opening paths in your editor
91+
92+
If you passed a path to `snap_compare`, you can quickly open the path in your editor by setting the `TEXTUAL_SNAPSHOT_FILE_OPEN_PREFIX` environment variable based on the editor you want to use. Clicking on the path in the snapshot report will open the path in your editor.
93+
94+
- `file://` - default, most likely opening in your browser
95+
- `code://file/` - opens the path in VS Code
96+
- `cursor://file/` - opens the path in Cursor
97+
- `pycharm://` - opens the path in PyCharm
98+

0 commit comments

Comments
 (0)