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

Use snapshot tests instead of HTML fixtures #42

Merged
merged 10 commits into from
Jun 7, 2023

Conversation

jams2
Copy link
Collaborator

@jams2 jams2 commented Apr 12, 2023

Closes #41

This PR adds syrupy, a pytest plugin for snapshot tests, to the project. The aim of this is to remove the need for manual maintenance of HTML fixtures.

In addition to adding syrupy, this PR:

  • adds a custom syrupy extension class, to write fixtures as one-HTML-file-per-snapshot (the default is many snapshots in a file);
  • removes the HTML fixtures; and
  • adds snapshots for all existing component rendering tests.

The snapshots shouldn't need individual comparison with the old fixtures - they were generated from main branch, where all tests were passing.

@jams2 jams2 marked this pull request as ready for review April 19, 2023 16:31
@jams2
Copy link
Collaborator Author

jams2 commented Apr 19, 2023

I changed the poetry CI cache key to include the full Python version (as per this) and it fixed the Python test job. It seems that there has been a Python bugfix release that was not playing nicely with the poetry environment built on an older version.

pyproject.toml Outdated Show resolved Hide resolved
tests/utils.py Outdated Show resolved Hide resolved
tests/utils.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@jams2
Copy link
Collaborator Author

jams2 commented Apr 26, 2023

I've added djlint as a dev dependency. I went with djlint over djhtml as the former does autoformatting. My thinking is that we should autoformat the snapshots, so they are easy to read in code review if they are changed. Reading diffs of single-line HTML is a nightmare.

If we format the snapshots, we also need to format the rendered markup they are compared with. So, I've added a call to djlint's auto-formatter to the render_form and render_template utils.

I've also added linting of templates with djlint. Personally I don't feel that we need to enforce formatting for templates, but happy to change that. (also, I don't love how djlint formats hanging attributes, and it's not configurable)

Linting and format checks have been added to pre-commit and CI.

pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
@jams2 jams2 merged commit 02488bc into torchbox:main Jun 7, 2023
2 checks passed
@jams2 jams2 deleted the feature/snapshot-tests branch June 7, 2023 08:40
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.

Find a way to automate updating the HTML fixtures
3 participants