syrusakbary / snapshottest

Snapshot Testing utils for Python 📸
MIT License
525 stars 102 forks source link

Having a dict with the key "self" does not work #147

Closed estyrke closed 3 years ago

estyrke commented 3 years ago

If a snapshot contains a (possibly nested) dict with a key named "self", snapshottest will crash in the SortedDict constructor with the error TypeError: __init__() got multiple values for argument 'self'. There doesn't seem to be an obvious solution, because whatever name is chosen for the self parameter in SortedDict.__init__, it risks colliding with the incoming dict keys. Calling it something more contrived, like __SortedDict__self__ might mitigate the problem.

Minimal pytest example:

def test_self(snapshot):
    snapshot.assert_match({"self": 1})
estyrke commented 3 years ago

Apparently, the problematic code does not exist in 0.6.0 anymore, so maybe the issue is solved already. It doesn't seem to be available on pypi yet though.

paulmelnikow commented 3 years ago

The latest release is 1.0.0a0 which is on PyPI. Want to give that a try?

Screen Shot 2020-10-24 at 9 26 09 AM
estyrke commented 3 years ago

Not sure what I did wrong last time, but indeed, 0.6.0 has fixed this issue, and 1.0.0a0 works as well.