How can I mock out the base class to test the rest behaviour of derived class?
# themod/sql.py
class PostgresStore(object):
def __init__(self, host, port):
self.host = host
self.port = port
def connect(self):
self._conn = "%s:%s" % (self.host, self.port)
return self._conn
# themod/repository.py
from .sql import PostgresStore
class Repository(PostgresStore):
def freak_count(self):
pass
# tests/test.py
from themod.repository import Repository
from mock import patch
@patch('themod.repository.PostgresStore', autospec=True)
def patched(thepatch):
# print(thepatch)
x = Repository('a', 'b')
#### how to mock the call to x.connect?
print(x.connect())
patched()
Aucun commentaire:
Enregistrer un commentaire