Closed jandom closed 1 year ago
syrupy writes files so you can't mock file IO interactions.
In general, I wouldn't recommend mocking built-ins at all and instead would recommend writing to temp directories.
If you absolutely must mock open
, then you need to scope the mock to just the code you're testing. E.g.:
def test_foo(snapshot):
with patch("builtins.open", new_callable=mock_open) as mock_builtins_open:
result = foo()
assert result == snapshot
Thanks @noahnu, that's awesome and it worked for me. Not knowing the internals of pytest, I sort of assumed some isolation between a pytest fixture and the mocking... :P
What's your question?
hi there, i've tried to mix syrup with unittest.mock patch and appear to have stumbled on a problem
Here is my simple example
This will never pass, syrup always reports that
You can generate the snapshot on a loop, nothing happens until the mock is removed
Then everything works but obviously I want to avoid writing to the file in the test. Is there any way to mix mock and syrup?