ejecución de la función o bloque with from unittest.mock import patch with patch('path.to.module.Class.method', autospec=True) as mocked_method: pass @henocdz 24
call to external service return True def send_invites(phones): sent_to = [] for phone in phones: sent = send_sms(phone=phone, message='Invitación...') if sent: sent_to.append(phone) return True, sent_to @henocdz 33
@mock_s3 def test_my_model_save(): conn = boto3.resource('s3', region_name='us-east-1') # We need to create the bucket since this is all in Moto's 'virtual' AWS account conn.create_bucket(Bucket='mybucket') model_instance = MyModel('steve', 'is awesome') model_instance.save() body = conn.Object('mybucket', 'steve').get()['Body'].read().decode("utf-8") assert body == b'is awesome' @henocdz 43