'Test that when scaling if the API returns an error, that error is handled
and the remaining threads continue.'

def test_scale_with_api_error(self):

    service = self.create_service(u'web')
    next_number = service._next_container_number()
    service.create_container(number=next_number, quiet=True)
    with mock.patch(u'compose.container.Container.create', side_effect=APIError(message=u'testing', response={}, explanation=u'Boom')):
        with mock.patch(u'sys.stderr', new_callable=StringIO) as mock_stderr:
            with pytest.raises(OperationFailedError):
                service.scale(3)
    assert (len(service.containers()) == 1)
    assert service.containers()[0].is_running
    assert (u'ERROR:    for    composetest_web_2        Cannot    create    container    for    service    web:    Boom' in mock_stderr.getvalue())
