MORSECorp / snappiershot

Apache License 2.0
30 stars 2 forks source link

[BUG] Fails with Mocker #80

Open TinyTheBrontosaurus opened 3 years ago

TinyTheBrontosaurus commented 3 years ago

Describe the bug Using mocker causes a failure during serialization. It appears snappiershot is trying to serialize the mocker object but is unable to do so

To Reproduce Write a simple test using mocker:

def test_mocker(snapshot, mocker):
    snapshot.assert_match(1)

produces the following call stack

/home/ttb/.venv/bin/python /home/ttb/ttb/test/test_tag_usb.py
Traceback (most recent call last):
  File "/home/ttb/ttb/test/test_tag_usb.py", line 160, in <module>
    test_mocker(snapshot, mock)
  File "/home/ttb/.venv/lib/python3.7/site-packages/snappiershot/snapshot.py", line 188, in __exit__
    self._snapshot_file.write()
  File "/home/ttb/.venv/lib/python3.7/site-packages/snappiershot/snapshot.py", line 430, in write
    sort_keys=True,
  File "/home/ttb/.pyenv/versions/3.7.3/lib/python3.7/json/__init__.py", line 179, in dump
    for chunk in iterable:
  File "/home/ttb/.pyenv/versions/3.7.3/lib/python3.7/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/home/ttb/.pyenv/versions/3.7.3/lib/python3.7/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/home/ttb/.pyenv/versions/3.7.3/lib/python3.7/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/home/ttb/.pyenv/versions/3.7.3/lib/python3.7/json/encoder.py", line 325, in _iterencode_list
    yield from chunks
  File "/home/ttb/.pyenv/versions/3.7.3/lib/python3.7/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/home/ttb/.pyenv/versions/3.7.3/lib/python3.7/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/home/ttb/.pyenv/versions/3.7.3/lib/python3.7/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/home/ttb/.pyenv/versions/3.7.3/lib/python3.7/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/home/ttb/.venv/lib/python3.7/site-packages/snappiershot/serializers/json.py", line 80, in default
    f"Encoding for this object is not yet implemented: {value} ({type(value)})"
NotImplementedError: Encoding for this object is not yet implemented: <module 'mock' from '/home/ttb/.venv/lib/python3.7/site-packages/mock/__init__.py'> (<class 'module'>)

Process finished with exit code 1

Expected behavior Not crashing?

Screenshots

Versions:

Additional context Add any other context about the problem here.

TinyTheBrontosaurus commented 3 years ago

update: with snappiershot 1.0.0, the error is different. It ends up with infinite recursion.

bbonenfant commented 3 years ago

Thanks for the bug reports! We are still working to figure this out how to fix this bug, but it most likely has to do with the complex nature of those Mocker objects. Just wanted to let you know that we are working on this

tahoeschrader commented 2 years ago

due to complex nature of mocker objects, current developers suggest not to snapshot them and ignoring them in the metadata via ignore=["name_of_mocker_obj_variable"] in the assert_match call for the time being until they can be ignored in the same manner that snappiershot ignores itself and replace trying to snapshot itself with just snapshotting a string that says "MockFixture", etc.