test(core): close transport in `BackgroundDeviceHandler.kill_task()`
What changed, and why it matters
This commit fixes a test helper so it properly closes the USB/transport connection when a background test task is killed. It only touches test code, not the firmware or production wallet code, so it has no direct security impact on real Trezor devices or users.
No security action required; this is a test-infrastructure cleanup. Treat as a normal code-quality/test-fix review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change restores self.client.transport.close() inside BackgroundDeviceHandler.kill_task() in the test harness. A previous commit (78ecfb2caac98337fae74ea1d6f607c7cf015395) had removed that close, leaving background device tasks waiting on I/O instead of being interrupted. Two click tests are updated to match the restored behavior: one no longer manually closes the transport before kill_task(), and another reopens the transport and uses messages.Cancel() instead of session.cancel() after the kill. All changes are confined to the tests/ directory.
Changed components
tests/device_handler.pytests/click_tests/device_menu/test_notifications.pytests/click_tests/test_recovery.pyInspect captured patch +9 / −3
diff --git a/tests/click_tests/device_menu/test_notifications.py b/tests/click_tests/device_menu/test_notifications.py
index a3a733f7..c29b6b10 100644
--- a/tests/click_tests/device_menu/test_notifications.py
+++ b/tests/click_tests/device_menu/test_notifications.py
@@ -19,6 +19,7 @@ from typing import TYPE_CHECKING
import pytest
from trezorlib import device, messages
+from trezorlib.exceptions import Cancelled
from ... import translations as TR
from .. import reset
@@ -155,10 +156,15 @@ def test_backup_failed(
# read words
reset.read_words(debug, do_htc=False, confirm_instruction=True)
+ # stop at words' confirmation
+ debug.synchronize_at("SelectWordScreen")
device_handler.kill_task()
+ # the transport is closed by `kill_task` above
+ session.client.transport.open()
# Raise the loop restart exception to reset the flow
- session.cancel()
+ with pytest.raises(Cancelled):
+ session.call(messages.Cancel())
# Wait for the homescreen to appear
debug.synchronize_at("Homescreen")
diff --git a/tests/click_tests/test_recovery.py b/tests/click_tests/test_recovery.py
index 86f6292e..be3136f9 100644
--- a/tests/click_tests/test_recovery.py
+++ b/tests/click_tests/test_recovery.py
@@ -185,7 +185,6 @@ def test_recovery_cancel_issue4613(device_handler: "BackgroundDeviceHandler"):
recovery.confirm_recovery(debug, title=title)
# select number of words
recovery.select_number_of_words(debug, num_of_words=12)
- device_handler.client.transport.close()
# abort the process running the recovery from host
device_handler.kill_task()
diff --git a/tests/device_handler.py b/tests/device_handler.py
index f25ec704..afec20af 100644
--- a/tests/device_handler.py
+++ b/tests/device_handler.py
@@ -102,9 +102,10 @@ class BackgroundDeviceHandler:
def kill_task(self) -> None:
if self.task is not None:
- # Force close the client, which should raise an exception in a client
+ # Force close the transport, which should raise an exception in a client
# waiting on IO. Does not work over Bridge, because bridge doesn't have
# a close() method.
+ self.client.transport.close()
try:
self.task.result(timeout=1)
except Exception:
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.