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

Introduce proper snapshot testing #80

Merged
merged 6 commits into from
Jul 16, 2024
Merged

Conversation

bbannier
Copy link
Member

This PR adds "proper" snapshot testing instead of the manual process of updating tests/data/test1.zeek and tests/data/test1.zeek.out.

@bbannier bbannier self-assigned this Jul 15, 2024
@bbannier bbannier marked this pull request as ready for review July 15, 2024 08:50
@bbannier bbannier requested a review from awelzel July 16, 2024 06:22
Copy link

@awelzel awelzel left a comment

Choose a reason for hiding this comment

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

I have no strong opinion or knowledge if syrupy is the proper tool to use, but seems quite nice. It does add a dependency on pytest, but appears ok to me, too.

tests/test_samples.py Outdated Show resolved Hide resolved
tests/test_samples.py Show resolved Hide resolved
tests/__snapshots__/test_samples.ambr Outdated Show resolved Hide resolved
tests/data/test1.zeek.out Outdated Show resolved Hide resolved
@bbannier bbannier force-pushed the topic/bbannier/snapshot-testing branch from c805016 to cc30511 Compare July 16, 2024 13:22
@bbannier bbannier requested a review from awelzel July 16, 2024 13:24
tests/test_formatting.py Show resolved Hide resolved
tests/testutils.py Show resolved Hide resolved
tests/test_samples.py Outdated Show resolved Hide resolved
tests/test_samples.py Show resolved Hide resolved
bbannier added 6 commits July 16, 2024 19:29
We are currently using a huge file `tests/data/test1.zeek` for manual
"snapshot testing". The idea is that one would add samples to the file
and then manually update the baseline `tests/data/test1.zeek.out`. As
this file grows this manual process becomes very cumbersome.
Additionally when the test fails it can be very hard to identify which
parts of the baseline differed.

This patch introduces a dedicated test `test_samples` which automates
this. The idea is that one would add new compact samples to
`test/samples` which the test discovers automatically. When the test is
run equality assertions are automatically routed to checks against
managed snapshots which can be updated with `pytest --snapshot-update`.
This should reduce overhead from adding/updating snapshots which should
make it easier to add coverage. We will migrate the existing tests over
in follow-up commits.
This test file is used for e.g., CLI tests and we want to keep it even
with snapshot tests. This patch simplifies it so it is easier to
maintain while still performing some formatting.
All source changes in this patch are created automatically from `black`.
These test files were used in a couple of tests but didn't need to be
standalone. This patch moves them into `testutils`.
@bbannier bbannier force-pushed the topic/bbannier/snapshot-testing branch from cc30511 to fbb835c Compare July 16, 2024 17:30
@bbannier bbannier merged commit f8b6570 into main Jul 16, 2024
7 checks passed
@bbannier bbannier deleted the topic/bbannier/snapshot-testing branch July 16, 2024 17:31
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