When I am mocking some interaction with MagicMock and found that following works to produce snapshot, but fails to validate snapshot afterwards:
from unittest.mock import patch
from assertpy import assert_that
from io import StringIO
def foo():
print('Something')
@patch('sys.stdout')
def test(mock_stdout):
foo()
assert_that(mock_stdout.method_calls).snapshot()
If we invoke test() method twice, then on second invocation it fails, while it should not:
>>> test()
>>> test()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/[email protected]/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/mock.py", line 1337, in patched
return func(*newargs, **newkeywargs)
File "<stdin>", line 4, in test
File "/Users/ignatzapolsky/.local/share/virtualenvs/RevLab-IOTIntegration-432zSlDD/lib/python3.9/site-packages/assertpy/snapshot.py", line 199, in snapshot
return self.is_equal_to(snap[lineno])
File "/Users/ignatzapolsky/.local/share/virtualenvs/RevLab-IOTIntegration-432zSlDD/lib/python3.9/site-packages/assertpy/base.py", line 126, in is_equal_to
self.error('Expected <%s> to be equal to <%s>, but was not.' % (self.val, other))
File "/Users/ignatzapolsky/.local/share/virtualenvs/RevLab-IOTIntegration-432zSlDD/lib/python3.9/site-packages/assertpy/assertpy.py", line 433, in error
raise AssertionError(out)
AssertionError: Expected <[call.write('Something'), call.write('\n')]> to be equal to <[['write', ['Something'], {}], ['write', ['\n'], {}]]>, but was not.
When I am mocking some interaction with MagicMock and found that following works to produce snapshot, but fails to validate snapshot afterwards:
If we invoke
test()method twice, then on second invocation it fails, while it should not: