Jack Sundberg
02/22/2021, 2:05 AMZanie
02/22/2021, 4:52 PMMagicMock
at least. It's the same as a Mock
but it has a few of the python built-ins implemented so it's easier to use, I wouldn't worry about that part. Basically you set some function that you're not interested in having actually run to a MagicMock
e.g. <http://http.Client.post|http.Client.post> = MagicMock()
now you can assert that the post
method was called with some expected arguments without it actually hitting the internet, e.g. http.Client.post.assert_called_once_with(url="<http://hello.com|hello.com>")
. It will also return mocks for attributes so for the example above we could have mocked http.Client = MagicMock()
and (generally) still be able to assert calls on attributes http.Client.post.assert...
Jack Sundberg
02/22/2021, 5:08 PMZanie
02/22/2021, 5:09 PM