mysql_info: Explanation unit-test #122
-
As per discussion here: #115 I'm trying to understand how this unit test works.
We have a function After the function definition it gets executed (without parameters):
Question: why Then the module gets executed:
Again the Last the assert:
There a comparision is done. However I don't understand what |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Let's take this one step at a time: When a method is called on a
And we mocked it as such:
Then Now, on to our code, there's a bunch of magic here: If the cursor's After the function is defined, we define the variable Then we instantiate Finally, in the The call to To wrap up, the decorator |
Beta Was this translation helpful? Give feedback.
Let's take this one step at a time:
MagicMock() is part of the standard unittest.mock library and it's its implementation of a mock object, the purpose of which is to replace an actual object with a simulation whose behavior we can control.
When a method is called on a
MagicMock
instance, the default behavior is to return anotherMagickMock
object. Generally you can modify this behaviour by setting thereturn_value
attribute. When the desired effects of a call on a particular method of theMagicMock
class are more complex than simply returning a value, e.g. the value needs to change in subsequent calls, an exception needs to be raised, or any other complex behaviour, this can be accomplis…