Skip to content

Crash with SingleFileSnapshotExtension #749

@rotu

Description

@rotu

Describe the bug

SingleFileSnapshotExtension crashes when trying to serialize a Dict with a number value.

To reproduce

run pytest --snapshot-update on a file containing the below test:

from syrupy.extensions.single_file import SingleFileSnapshotExtension
from syrupy.extensions.amber import AmberSnapshotExtension
def test_foo(snapshot):
    value = {"x": 0}
    # this works:
    assert value == snapshot(extension_class=AmberSnapshotExtension)
    #this does not:
    assert value == snapshot(extension_class=SingleFileSnapshotExtension)

Expected behavior

The test should generate a snapshot file without errors.

Screenshots

>       assert value == snapshot(extension_class=SingleFileSnapshotExtension)
E       assert [+ received] == [- snapshot]
E         TypeError: 'str' object cannot be interpreted as an integer
E         Traceback (most recent call last):
E           File ".../site-packages/syrupy/assertion.py", line 268, in _assert
E             serialized_data = self._serialize(data)
E                               ^^^^^^^^^^^^^^^^^^^^^
E           File ".../site-packages/syrupy/assertion.py", line 181, in _serialize
E             return self.extension.serialize(
E                    ^^^^^^^^^^^^^^^^^^^^^^^^^
E           File ".../site-packages/syrupy/extensions/single_file.py", line 52, in serialize
E             return self.get_supported_dataclass()(data)
E                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

test_x.py:24: AssertionError

Environment (please complete the following information):

  • OS: macOS 13.5
  • Syrupy Version: 4.0.2
  • Python Version: CPython 3.11.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentation

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions