Created
June 26, 2019 15:54
-
-
Save stepankuzmin/ab849b8b9eb50bbe7cead5cb6c578131 to your computer and use it in GitHub Desktop.
aiohttp + pytest + unittest mock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aiohttp | |
| from asyncio import Future | |
| from unittest.mock import MagicMock, Mock, patch | |
| def test_taxi_route_info(aiohttp_client, loop): | |
| async def taxi_route_info(): | |
| connector = aiohttp.TCPConnector(ssl=False) | |
| session = aiohttp.ClientSession(connector=connector, loop=loop) | |
| taxi_route_info = TaxiRouteInfo(session=session) | |
| taxi_info = await session.get('https://...') | |
| await session.close() | |
| assert True == True | |
| with patch('aiohttp.client.ClientSession.get') as mock_get: | |
| response = aiohttp.ClientResponse(method='GET', url='/', ...) | |
| mock_get.return_value = Future() | |
| mock_get.return_value.set_result(response) | |
| loop.run_until_complete(taxi_route_info()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment