0

I am trying to mock AWS service in python.

Usually, I mock AWS service which is defined globally.

But is it possible to mock, if it is defined inside the function?

eg.

def somefunction(replication_region):
   s3 = boto3.client("s3", region_name=replication_region)

This is a common function, which will be invoked if there are replication region is present for s3, if replication region is not present, then only one region will be executed.

So this variable is not defined globally.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
Gowtham Chand
  • 653
  • 3
  • 10
  • 17
  • Just mock `boto3.client`? then the mocked return value will be the value of `s3`. – sytech Mar 27 '18 at 14:27
  • 1
    boto3 has mocking support built in. See https://stackoverflow.com/questions/37143597/mocking-boto3-s3-client-method-python for some details – lxop Mar 27 '18 at 14:28
  • Possible duplicate of [Mocking boto3 S3 client method Python](https://stackoverflow.com/questions/37143597/mocking-boto3-s3-client-method-python) – lxop Mar 27 '18 at 14:29
  • there is also the [moto](https://github.com/spulec/moto) package – avigil Mar 27 '18 at 14:29
  • I am using patch, I am not able to access the variable inside the function – Gowtham Chand Mar 27 '18 at 15:24

0 Answers0