tophat / syrupy

:pancakes: The sweeter pytest snapshot plugin
https://tophat.github.io/syrupy
Apache License 2.0
501 stars 33 forks source link

fix: diffing excessively large snapshot lines #778

Closed iamogbz closed 1 year ago

iamogbz commented 1 year ago

Description

Limit the amount of characters used when comparing line diffs.

Can be validated by changing DIFF_LINE_WIDTH_LIMIT to a value like 1000000 and running inv test -t test_diff_large_lines

Related Issues

Checklist

Additional Comments

def test_large_binary_diff(snapshot):
    b = b"\x01" * 1000000
    assert b == snapshot.use_extension(SingleFileSnapshotExtension)
(syrupy-py3.11) ➜  syrupy git:(test-single-file-fix) ✗ inv test -vv -t test_large_binary_diff
============================== test session starts ==============================
platform darwin -- Python 3.11.4, pytest-7.4.0, pluggy-1.2.0 -- /Users/Emmanuel/Sources/github/tophat/syrupy/.venv/bin/python
cachedir: .pytest_cache
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /Users/Emmanuel/Sources/github/tophat/syrupy
configfile: pyproject.toml
plugins: syrupy-4.0.7, xdist-3.3.1, benchmark-4.0.0
collected 259 items / 258 deselected / 1 selected                               

tests/syrupy/extensions/test_single_file.py::test_large_binary_diff FAILED

=================================== FAILURES ====================================
____________________________ test_large_binary_diff _____________________________

snapshot = SnapshotAssertion(name='snapshot', num_executions=0)

    def test_large_binary_diff(snapshot):
        b = b"\x01" * 1000000
>       assert b == snapshot.use_extension(SingleFileSnapshotExtension)
E       AssertionError: assert [+ received] == [- snapshot]
E         Snapshot 'test_large_binary_diff' does not exist!
E         + b'\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x...

tests/syrupy/extensions/test_single_file.py:77: AssertionError
---------------------------- snapshot report summary ----------------------------
1 snapshot failed.
============================ short test summary info ============================
FAILED tests/syrupy/extensions/test_single_file.py::test_large_binary_diff - AssertionError: assert [+ received] == [- snapshot]
======================= 1 failed, 258 deselected in 0.21s =======================

Follow up to #776

tophat-opensource-bot commented 1 year ago

:tada: This PR is included in version 4.0.8 :tada:

The release is available on:

Your semantic-release bot :package::rocket: