Skip to content Skip to sidebar Skip to footer

Pytest - Patched Method Of A Class Does Not Return The Mock Value

My code is fairly simple but i don't understand what is going on : class MyDb : def some_func( arg ) : .... while my test code is : @mock.patch(mypkg.mydb) @pytest.mark.par

Solution 1:

some_func is a instance method, so it is called on an instance of MyDb, not the class itself. An instance is a return value from calling a class. So you need to bear that in mind when you patch.

mock_db.return_value.some_func.return_value = dummy_value

Post a Comment for "Pytest - Patched Method Of A Class Does Not Return The Mock Value"