Skip to content

Saved snapshot fails to match if repr ends with newline #925

@PhilReinhold

Description

@PhilReinhold

Describe the bug

It appears that if you snapshot test against an object whose repr ends in a newline, then the test will fail even after running --snapshot-update

To reproduce

# test_syrupy.py
class X:
    def __repr__(self):
        return "X\n"


def test_syrupy(snapshot):
    assert X() == snapshot

Then run pytest test_syrupy.py --snapshot-update then pytest teest_syrupy.py

The test fails with the following output

test_syrupy.py F                                                                                                                                                                                         [100%]

=================================================================================================== FAILURES ===================================================================================================
_________________________________________________________________________________________________ test_syrupy __________________________________________________________________________________________________

snapshot = X

    def test_syrupy(snapshot):
>       assert X() == snapshot
E       assert [+ received] == [- snapshot]
E         - X
E         + X␤

Expected behavior

I expect the test to pass

Environment (please complete the following information):

  • OS: MacOS 14.7
  • Syrupy Version: 4.8.0
  • Python Version: 3.11.4

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomersserializerSyrupy serializer question

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions