test(core): fix broken log suppression in unit tests
What changed, and why it matters
This commit only changes the test code for the Trezor firmware. It fixes how debug logging is suppressed during unit tests by moving the suppression logic into the shared test runner, instead of having each test file call a helper function. There is no change to the actual wallet firmware that users rely on, and no security vulnerability is being fixed.
No security action required. Treat as a normal test-maintenance commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors log suppression in the core test suite. It removes per-test-class calls to thp_common.suppress_debug_log() and the helper itself, and instead adds a DISABLE_LOG flag and a TestRunner.init that applies a log filter when running on debug builds with USE_DBG_CONSOLE. The change is purely in test infrastructure (core/tests/*) and does not touch production firmware code.
Changed components
core/tests/unittest.pycore/tests/thp_common.pycore/tests/test_apps.bitcoin.approver.pycore/tests/test_apps.bitcoin.authorization.pycore/tests/test_apps.bitcoin.keychain.pycore/tests/test_apps.common.keychain.pycore/tests/test_apps.ethereum.keychain.pycore/tests/test_storage.cache.pycore/tests/test_trezor.wire.thp.crypto.pycore/tests/test_trezor.wire.thp.writer.pycore/tests/README.mdInspect captured patch +15 / −35
diff --git a/core/tests/README.md b/core/tests/README.md
index bfc53d42..be489d6a 100644
--- a/core/tests/README.md
+++ b/core/tests/README.md
@@ -30,3 +30,6 @@ class TestSomething(unittest.TestCase):
```
Usage of `assert` is discouraged because it is not evaluated in production code (when `PYOPT=1`). Use `self.assertXY` instead, see `unittest.py`.
+
+## Logging
+By default, logging in unittests (using `trezor.log`) is disabled _even_ on debug builds. To enable logging, set `DISABLE_LOG` in `unittest.py` to `False`.
diff --git a/core/tests/test_apps.bitcoin.approver.py b/core/tests/test_apps.bitcoin.approver.py
index 71e24879..0158cb33 100644
--- a/core/tests/test_apps.bitcoin.approver.py
+++ b/core/tests/test_apps.bitcoin.approver.py
@@ -32,8 +32,6 @@ class TestApprover(unittest.TestCase):
if utils.USE_THP:
def setUpClass(self):
- if __debug__:
- thp_common.suppress_debug_log()
thp_common.prepare_context()
else:
diff --git a/core/tests/test_apps.bitcoin.authorization.py b/core/tests/test_apps.bitcoin.authorization.py
index 70ce988d..e07b8622 100644
--- a/core/tests/test_apps.bitcoin.authorization.py
+++ b/core/tests/test_apps.bitcoin.authorization.py
@@ -25,8 +25,6 @@ class TestAuthorization(unittest.TestCase):
if utils.USE_THP:
def setUpClass(self):
- if __debug__:
- thp_common.suppress_debug_log()
thp_common.prepare_context()
else:
diff --git a/core/tests/test_apps.bitcoin.keychain.py b/core/tests/test_apps.bitcoin.keychain.py
index 9a32762f..fe59c639 100644
--- a/core/tests/test_apps.bitcoin.keychain.py
+++ b/core/tests/test_apps.bitcoin.keychain.py
@@ -20,8 +20,6 @@ class TestBitcoinKeychain(unittest.TestCase):
if utils.USE_THP:
def setUpClass(self):
- if __debug__:
- thp_common.suppress_debug_log()
thp_common.prepare_context()
def setUp(self):
@@ -119,8 +117,6 @@ class TestAltcoinKeychains(unittest.TestCase):
if utils.USE_THP:
def setUpClass(self):
- if __debug__:
- thp_common.suppress_debug_log()
thp_common.prepare_context()
def setUp(self):
diff --git a/core/tests/test_apps.common.keychain.py b/core/tests/test_apps.common.keychain.py
index bd93244c..570e4277 100644
--- a/core/tests/test_apps.common.keychain.py
+++ b/core/tests/test_apps.common.keychain.py
@@ -24,8 +24,6 @@ class TestKeychain(unittest.TestCase):
if utils.USE_THP:
def setUpClass(self):
- if __debug__:
- thp_common.suppress_debug_log()
thp_common.prepare_context()
else:
diff --git a/core/tests/test_apps.ethereum.keychain.py b/core/tests/test_apps.ethereum.keychain.py
index 09564027..9e60f933 100644
--- a/core/tests/test_apps.ethereum.keychain.py
+++ b/core/tests/test_apps.ethereum.keychain.py
@@ -83,8 +83,6 @@ class TestEthereumKeychain(unittest.TestCase):
if utils.USE_THP:
def setUpClass(self):
- if __debug__:
- thp_common.suppress_debug_log()
thp_common.prepare_context()
def setUp(self):
diff --git a/core/tests/test_storage.cache.py b/core/tests/test_storage.cache.py
index 16fe8102..ee7892d0 100644
--- a/core/tests/test_storage.cache.py
+++ b/core/tests/test_storage.cache.py
@@ -37,11 +37,6 @@ class TestStorageCache(unittest.TestCase):
if utils.USE_THP:
- def setUpClass(self):
- if __debug__:
- thp_common.suppress_debug_log()
- super().__init__()
-
def setUp(self):
self.interface = MockHID()
cache.clear_all()
diff --git a/core/tests/test_trezor.wire.thp.crypto.py b/core/tests/test_trezor.wire.thp.crypto.py
index 4ae87dc1..a59e77ad 100644
--- a/core/tests/test_trezor.wire.thp.crypto.py
+++ b/core/tests/test_trezor.wire.thp.crypto.py
@@ -77,11 +77,6 @@ class TestTrezorHostProtocolCrypto(unittest.TestCase):
(0xFFFFFFFFFFFFFFFF, b"\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff"),
]
- def __init__(self):
- if __debug__ and utils.USE_THP:
- thp_common.suppress_debug_log()
- super().__init__()
-
def test_encryption(self):
for v in self.vectors_enc:
buffer = bytearray(v[3])
diff --git a/core/tests/test_trezor.wire.thp.writer.py b/core/tests/test_trezor.wire.thp.writer.py
index d719fa80..488ff580 100644
--- a/core/tests/test_trezor.wire.thp.writer.py
+++ b/core/tests/test_trezor.wire.thp.writer.py
@@ -73,11 +73,6 @@ class TestTrezorHostProtocolWriter(unittest.TestCase):
while True:
task.send(None)
- def __init__(self):
- if __debug__ and utils.USE_THP:
- thp_common.suppress_debug_log()
- super().__init__()
-
def setUp(self):
self.interface = MockHID()
thp_ctx = ThpContext(self.interface)
diff --git a/core/tests/thp_common.py b/core/tests/thp_common.py
index b4037128..a914dbcc 100644
--- a/core/tests/thp_common.py
+++ b/core/tests/thp_common.py
@@ -29,11 +29,3 @@ if utils.USE_THP:
thp_ctx = ThpContext(iface)
(iface_ctx,) = thp_ctx._iface_ctxs
return Channel(channel_cache, iface_ctx, (ThpBuffer(), ThpBuffer()))
-
-
-if __debug__:
- # Disable log.debug
- def suppress_debug_log() -> None:
- from trezor import log
-
- log._min_level = 1
diff --git a/core/tests/unittest.py b/core/tests/unittest.py
index 2bb672fe..55b4d88d 100644
--- a/core/tests/unittest.py
+++ b/core/tests/unittest.py
@@ -7,6 +7,8 @@ ERROR_COLOR = "\033[31m"
OK_COLOR = "\033[32m"
SKIPPED_COLOR = "\033[33m"
+DISABLE_LOG = True
+
class SkipTest(Exception):
pass
@@ -227,6 +229,16 @@ class TestSuite:
class TestRunner:
+
+ def __init__(self):
+ if __debug__ and DISABLE_LOG:
+ from trezor.utils import USE_DBG_CONSOLE
+
+ if USE_DBG_CONSOLE:
+ from trezor.utils import set_log_filter
+
+ set_log_filter("-*")
+
def run(self, suite):
res = TestResult()
for c in suite.tests:
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.