Skip to content

Update tests to improve CI logging to better diagnose timeout #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: poetry install
shell: bash
- name: Test with Pytest
run: poetry run pytest
run: poetry run pytest --log-cli-level=DEBUG -vv -s
shell: bash
release:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ select=["E", "F", "UP", "I"]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
timeout = 30
log_format = "%(asctime)s.%(msecs)03d %(levelname)s (%(threadName)s) [%(name)s] %(message)s"
14 changes: 12 additions & 2 deletions tests/devices/test_mqtt_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import json
import logging
from collections.abc import Callable, Generator
from unittest.mock import AsyncMock, Mock, patch

Expand Down Expand Up @@ -82,6 +83,15 @@ async def setup_message_handler(mqtt_session: Mock, mqtt_channel: MqttChannel) -
return message_handler


@pytest.fixture
def warning_caplog(
caplog: pytest.LogCaptureFixture,
) -> pytest.LogCaptureFixture:
"""Fixture to capture warning messages."""
caplog.set_level(logging.WARNING)
return caplog


async def home_home_data_no_devices() -> HomeData:
"""Mock home data API that returns no devices."""
return HomeData(
Expand Down Expand Up @@ -163,7 +173,7 @@ async def test_concurrent_commands(
mqtt_session: Mock,
mqtt_channel: MqttChannel,
mqtt_message_handler: Callable[[bytes], None],
caplog: pytest.LogCaptureFixture,
warning_caplog: pytest.LogCaptureFixture,
) -> None:
"""Test handling multiple concurrent RPC commands."""

Expand All @@ -187,7 +197,7 @@ async def test_concurrent_commands(
assert result1 == TEST_RESPONSE
assert result2 == TEST_RESPONSE2

assert not caplog.records
assert not warning_caplog.records


async def test_concurrent_commands_same_request_id(
Expand Down
7 changes: 6 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ async def connected_mqtt_client_fixture(
response_queue.put(mqtt_packet.gen_suback(1, 0))
await mqtt_client.async_connect()
yield mqtt_client
if mqtt_client.is_connected():
try:
await mqtt_client.async_disconnect()
except Exception:
pass


async def test_async_connect(received_requests: Queue, connected_mqtt_client: RoborockMqttClientV1) -> None:
Expand Down Expand Up @@ -207,7 +212,7 @@ async def test_disconnect_failure_response(
# further messages and there is no parsing error, and no failed log messages.
response_queue.put(mqtt_packet.gen_disconnect(reason_code=1))
assert connected_mqtt_client.is_connected()
with caplog.at_level(logging.ERROR, logger="homeassistant.components.nest"):
with caplog.at_level(logging.ERROR):
await connected_mqtt_client.async_disconnect()
assert not connected_mqtt_client.is_connected()
assert not caplog.records
Expand Down
Loading