def tearDown(self): objects = self.client.list_objects(Bucket=self.bucketName) if 'Contents' in objects: for item in objects['Contents']: self.client.delete_object(Bucket=self.bucketName, Key=item['Key']) self.client.delete_bucket(Bucket=self.bucketName) # unset any potentially set dummy credentials if self.usingDummyCredentials: unsetAwsEnvCredentials()
def tearDown(self): s3 = boto3.resource("s3") bucket = s3.Bucket(self.bucketName) try: bucket.objects.all().delete() except botocore.exceptions.ClientError as e: if e.response["Error"]["Code"] == "404": # the key was not reachable - pass pass else: raise bucket = s3.Bucket(self.bucketName) bucket.delete() # unset any potentially set dummy credentials if self.usingDummyCredentials: unsetAwsEnvCredentials()
def tearDown(self): s3 = boto3.resource("s3") bucket = s3.Bucket(self.bucketName) try: bucket.objects.all().delete() except botocore.exceptions.ClientError as err: errorcode = err.response["ResponseMetadata"]["HTTPStatusCode"] if errorcode == 404: # the key was not reachable - pass pass else: raise bucket = s3.Bucket(self.bucketName) bucket.delete() # unset any potentially set dummy credentials if self.usingDummyCredentials: unsetAwsEnvCredentials()