I have developed the logic where I am initializing a few variables but with two versions. Initially, my code looked something like this: session = boto3.session.Session() client = session.client( service_name='secretsmanager', region_name="eu-west-1" ) class MyRepo(object): So here, I was able to mock the client directly using a patch because it wasn't an instance variable. After I implemented dependency injection : class MyRepo(object): def __init__(self, region): session = boto3.session.Session() self.client = session.client( service_name='secretsmanager', region_name=region ) Now, I am trying to mock the instance variable which is accessed using the self keyword i.e client . @patch('credentials_repo.my_repo.client') class TestSecretManagerMethod(TestCase): However, when I run the test case it throws an error attached below: raise AttributeError( AttributeError: <module ...
A site where you can share knowledge