Skip to content

Commit f1dd1fe

Browse files
authored
Update tests to improve CI logging to better diagnose timeout (#411)
* chore: Remove tests that timeout on CI * chore: Enable verbose logging in CI * chore: Remove incorrect caplog package * chore: Fix CI logging * chore: Fix lint * chore: Change return type of caplog * chore: Update log format to include timining information and thread names
1 parent 0a63add commit f1dd1fe

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
run: poetry install
5151
shell: bash
5252
- name: Test with Pytest
53-
run: poetry run pytest
53+
run: poetry run pytest --log-cli-level=DEBUG -vv -s
5454
shell: bash
5555
release:
5656
runs-on: ubuntu-latest

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ select=["E", "F", "UP", "I"]
7676
asyncio_mode = "auto"
7777
asyncio_default_fixture_loop_scope = "function"
7878
timeout = 30
79+
log_format = "%(asctime)s.%(msecs)03d %(levelname)s (%(threadName)s) [%(name)s] %(message)s"

tests/devices/test_mqtt_channel.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
import json
5+
import logging
56
from collections.abc import Callable, Generator
67
from unittest.mock import AsyncMock, Mock, patch
78

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

8485

86+
@pytest.fixture
87+
def warning_caplog(
88+
caplog: pytest.LogCaptureFixture,
89+
) -> pytest.LogCaptureFixture:
90+
"""Fixture to capture warning messages."""
91+
caplog.set_level(logging.WARNING)
92+
return caplog
93+
94+
8595
async def home_home_data_no_devices() -> HomeData:
8696
"""Mock home data API that returns no devices."""
8797
return HomeData(
@@ -163,7 +173,7 @@ async def test_concurrent_commands(
163173
mqtt_session: Mock,
164174
mqtt_channel: MqttChannel,
165175
mqtt_message_handler: Callable[[bytes], None],
166-
caplog: pytest.LogCaptureFixture,
176+
warning_caplog: pytest.LogCaptureFixture,
167177
) -> None:
168178
"""Test handling multiple concurrent RPC commands."""
169179

@@ -187,7 +197,7 @@ async def test_concurrent_commands(
187197
assert result1 == TEST_RESPONSE
188198
assert result2 == TEST_RESPONSE2
189199

190-
assert not caplog.records
200+
assert not warning_caplog.records
191201

192202

193203
async def test_concurrent_commands_same_request_id(

tests/test_api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ async def connected_mqtt_client_fixture(
142142
response_queue.put(mqtt_packet.gen_suback(1, 0))
143143
await mqtt_client.async_connect()
144144
yield mqtt_client
145+
if mqtt_client.is_connected():
146+
try:
147+
await mqtt_client.async_disconnect()
148+
except Exception:
149+
pass
145150

146151

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

0 commit comments

Comments
 (0)