Upgrade pytest-aiohttp (#82475)
* Upgrade pytest-aiohttp * Make sure executors, tasks and timers are closed Some test will trigger warnings on garbage collect, these warnings spills over into next test. Some test trigger tasks that raise errors on shutdown, these spill over into next test. This is to mimic older pytest-aiohttp and it's behaviour on test cleanup. Discussions on similar changes for pytest-aiohttp are here: https://github.com/pytest-dev/pytest-asyncio/pull/309 * Replace loop with event_loop * Make sure time is frozen for tests * Make sure the ConditionType is not async /home-assistant/homeassistant/helpers/template.py:2082: RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited def wrapper(*args, **kwargs): Enable tracemalloc to get traceback where the object was allocated. See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info. * Increase litejet press tests with a factor 10 The times are simulated anyway, and we can't stop the normal event from occuring. * Use async handlers for aiohttp tests/components/motioneye/test_camera.py::test_get_still_image_from_camera tests/components/motioneye/test_camera.py::test_get_still_image_from_camera tests/components/motioneye/test_camera.py::test_get_stream_from_camera tests/components/motioneye/test_camera.py::test_get_stream_from_camera tests/components/motioneye/test_camera.py::test_camera_option_stream_url_template tests/components/motioneye/test_camera.py::test_camera_option_stream_url_template /Users/joakim/src/hass/home-assistant/venv/lib/python3.9/site-packages/aiohttp/web_urldispatcher.py:189: DeprecationWarning: Bare functions are deprecated, use async ones warnings.warn( * Switch to freezegun in modbus tests The tests allowed clock to tick in between steps * Make sure skybell object are fully mocked Old tests would trigger attempts to post to could services: ``` DEBUG:aioskybell:HTTP post https://cloud.myskybell.com/api/v3/login/ Request with headers: {'content-type': 'application/json', 'accept': '*/*', 'x-skybell-app-id': 'd2b542c7-a7e4-4e1e-b77d-2b76911c7c46', 'x-skybell-client-id': '1f36a3c0-6dee-4997-a6db-4e1c67338e57'} ``` * Fix sorting that broke after rebase
This commit is contained in:
parent
b7652c78ee
commit
c576a68d33
42 changed files with 263 additions and 226 deletions
|
@ -62,7 +62,7 @@ from tests.common import async_fire_time_changed
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def aiohttp_server(loop, aiohttp_server, socket_enabled):
|
||||
def aiohttp_server(event_loop, aiohttp_server, socket_enabled):
|
||||
"""Return aiohttp_server and allow opening sockets."""
|
||||
return aiohttp_server
|
||||
|
||||
|
@ -218,7 +218,7 @@ async def test_get_still_image_from_camera(
|
|||
) -> None:
|
||||
"""Test getting a still image."""
|
||||
|
||||
image_handler = Mock(return_value="")
|
||||
image_handler = AsyncMock(return_value="")
|
||||
|
||||
app = web.Application()
|
||||
app.add_routes(
|
||||
|
@ -258,7 +258,7 @@ async def test_get_still_image_from_camera(
|
|||
async def test_get_stream_from_camera(aiohttp_server: Any, hass: HomeAssistant) -> None:
|
||||
"""Test getting a stream."""
|
||||
|
||||
stream_handler = Mock(return_value="")
|
||||
stream_handler = AsyncMock(return_value="")
|
||||
app = web.Application()
|
||||
app.add_routes([web.get("/", stream_handler)])
|
||||
stream_server = await aiohttp_server(app)
|
||||
|
@ -341,7 +341,7 @@ async def test_camera_option_stream_url_template(
|
|||
"""Verify camera with a stream URL template option."""
|
||||
client = create_mock_motioneye_client()
|
||||
|
||||
stream_handler = Mock(return_value="")
|
||||
stream_handler = AsyncMock(return_value="")
|
||||
app = web.Application()
|
||||
app.add_routes([web.get(f"/{TEST_CAMERA_NAME}/{TEST_CAMERA_ID}", stream_handler)])
|
||||
stream_server = await aiohttp_server(app)
|
||||
|
@ -371,7 +371,7 @@ async def test_camera_option_stream_url_template(
|
|||
# the expected exception, then verify the right handler was called.
|
||||
with pytest.raises(HTTPBadGateway):
|
||||
await async_get_mjpeg_stream(hass, Mock(), TEST_CAMERA_ENTITY_ID)
|
||||
assert stream_handler.called
|
||||
assert AsyncMock.called
|
||||
assert not client.get_camera_stream_url.called
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue