I'm attempting to mock a class.
The class I'm attempting to mock looks like the following (lines have been removed for brevity):
class Connection(object):
"""Connection.
"""
def __init__(self, base_url=None, creds=None, user_agent=None):
self.clients = ClientFactory(self)
As you can see, it has a property called clients
.
My method under test:
def _auth(self, credentials):
connection = Connection(base_url=f'https://someurl.com', creds=credentials)
return connection.clients
My unit test looks like this:
@patch('connection.Connection.__init__')
def test_deploy(patched_connection, fs):
patched_connection.return_value = None
patched_connection.clients = None
# Do some stuff
The question is... how do I set the clients
property in my test as the method under test requires it to be set? (I can set it to None
, but I just need to be able to set it.)
With the current code, my application returns the error:
AttributeError: 'Connection' object has no attribute 'clients'
Thanks!