[Python] I mock the async generator and get an error

Discussão em 'Python' iniciado por Stack, Outubro 23, 2024.

  1. Stack

    Stack Membro Participativo

    FAILED tests/test_main.py::test_main - TypeError: 'async for' requires an object with aiter method, got coroutine

    with patch('url_shortener_service.main.MessageBroker') as MockMessageBroker, \
    patch('url_shortener_service.main.Cache') as MockCache, \
    patch('url_shortener_service.main.DataBase') as MockDataBase, \
    patch('url_shortener_service.main.check_short_url', new_callable=AsyncMock) as mock_check_short_url:

    mock_broker_instance = MockMessageBroker.return_value.__aenter__.return_value
    mock_broker_instance.consume_data.return_value.__aiter__.return_value = iter([
    json.dumps({"url": "http://example.com", "expiration": 3600, "prefix": "short"})
    ])```


    tried all possible options

    Continue reading...

Compartilhe esta Página