I am having a custom Db class, which has the basic operations. I am trying to write tests around it - on the __init__ of my class I am connecting to actual db which I want to avoid ( since I am just writing unit tests, no need to connect to the actual db ).
This is my code :
@mock.patch( 'mydb.Db' )
@pytest.mark.parametrize( "input,expected", [
(
{
'key' : "x" ,
'value' : 5 ,
} ,
[ "x = 5" ]
) ,
])
def test_where_statement( mock_db, input, expected):
mock_db.__init__.return_value = None
assert expected == mock_db.where( input[ "key"] , input[ "value" ] )._condition_list
It fails on the line where I set the return_value to None - issue is :
def test_where_statement( mock_db, input, expected):
> mock_db.__init__.return_value = None
E AttributeError: 'instancemethod' object has no attribute 'return_value'
I want to mock only the init function and then be able to run the where function ( which builds the where statement of my query for example ).
What am I missing?