Answer the question
In order to leave comments, you need to log in
Why is the replaced mock function not showing up in mock_calls?
I replace the mock function and after the replacement it is not displayed in mock_calls, how to fix it?
from unittest.mock import MagicMock, mock_open, patch
mo = mock_open()
def mywrite(b):
assert type(b) == bytearray or type(b) == bytes
assert b == b'data'
return len(b)
mo.return_value.write = mywrite
with patch("builtins.open", mo) as mock_file:
with open("a.mp3", "wb") as f:
total_size = f.write(b"data")
print("MP3 file size: ", total_size)
print(mock_file.mock_calls) # !!!***
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question