Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot testing #793

Merged
merged 48 commits into from
Sep 23, 2022
Merged

Snapshot testing #793

merged 48 commits into from
Sep 23, 2022

Conversation

darrenburns
Copy link
Member

@darrenburns darrenburns commented Sep 20, 2022

Adds snapshot testing features to the test suite, and a set of layout-related example tests. We can craft better example apps to do snapshots on in the future.

Basic view:

image

After toggling the "show difference" switch:

image

Link to the report will be written to your terminal in the event of a snapshot mismatch:

image

If you're running in CI, it'll be saved as a build artifact which you can download and view:

image

@darrenburns darrenburns marked this pull request as draft September 20, 2022 14:36
@darrenburns darrenburns changed the title Add docs for CSS variables Snapshot testing Sep 20, 2022
Comment on lines +46 to +51
- name: Upload snapshot report
if: always()
uses: actions/upload-artifact@v3
with:
name: snapshot-report-textual
path: tests/snapshot_tests/output/snapshot_report.html
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs on both failure and success. On success, there's no snapshot report, but the step still succeeds.

Comment on lines +5 to +6
test-snapshot-update:
pytest --cov-report term-missing --cov=textual tests/ -vv --snapshot-update
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this runs all tests, it'll update all snapshots.

@@ -0,0 +1,43 @@
# Snapshot Testing
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal docs

@@ -48,13 +48,15 @@ pre-commit = "^2.13.0"
pytest-aiohttp = "^1.0.4"
time-machine = "^2.6.0"
Jinja2 = "<3.1.0"
syrupy = "^3.0.0"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the snapshot testing library we're wrapping which handles associating pytest test functions with snapshots on disk.


[tool.black]
includes = "src"

[tool.pytest.ini_options]
asyncio_mode = "auto"
testpaths = ["tests"]
addopts = "--strict-markers"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should be the default - if you use an undefined marker it'll fail fast - good for catching typos.

@@ -0,0 +1,30 @@
def test_grid_layout_basic(snap_compare):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A selection of layout related tests to get us started.

@darrenburns darrenburns marked this pull request as ready for review September 22, 2022 13:42
@willmcgugan willmcgugan merged commit 824779e into css Sep 23, 2022
@willmcgugan willmcgugan deleted the snapshot branch September 23, 2022 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants