fix(core/tests): use decorator for unit tests skipping
What changed, and why it matters
This commit only changes how certain software tests are skipped or run. It replaces manual 'if' checks at the bottom of test files with Python's built-in '@unittest.skipUnless' decorator on test classes. This makes the test suite behave more consistently but does not change any actual product code that users interact with.
No security action required. Treat as a normal test-maintenance change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors unit-test gating logic across seven test files in core/tests/. Previously, tests were conditionally executed via ‘if name == “main”:’ guards checking utils.INTERNAL_MODEL, utils.USE_SD_CARD, etc. The change moves those conditions to @unittest.skipUnless decorators on the relevant classes and adds a missing ‘utils.USE_THP’ guard in two THP test init methods. No firmware runtime code, cryptographic logic, or device behavior is modified.
Changed components
core/tests/test_apps.bitcoin.signtx_decred.pycore/tests/test_apps.nem.hdnode.pycore/tests/test_trezor.io.fatfs.pycore/tests/test_trezor.io.sdcard.pycore/tests/test_trezor.sdcard.pycore/tests/test_trezor.wire.thp.crypto.pycore/tests/test_trezor.wire.thp.writer.pyInspect captured patch +14 / −15
diff --git a/core/tests/test_apps.bitcoin.signtx_decred.py b/core/tests/test_apps.bitcoin.signtx_decred.py
index 58b52fa3..0e6129eb 100644
--- a/core/tests/test_apps.bitcoin.signtx_decred.py
+++ b/core/tests/test_apps.bitcoin.signtx_decred.py
@@ -62,6 +62,7 @@ if utils.INTERNAL_MODEL in ("T2T1",): # pylint: disable=internal-model-tuple-co
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
+@unittest.skipUnless(utils.INTERNAL_MODEL == "T2T1", "only for T2T1")
class TestSignTxDecred(unittest.TestCase):
# pylint: disable=C0301
@@ -408,8 +409,4 @@ class TestSignTxDecred(unittest.TestCase):
if __name__ == "__main__":
- if utils.INTERNAL_MODEL in ( # pylint: disable=internal-model-tuple-comparison
- "T2T1",
- ):
-
- unittest.main()
+ unittest.main()
diff --git a/core/tests/test_apps.nem.hdnode.py b/core/tests/test_apps.nem.hdnode.py
index 8c41c4f1..d6e79840 100644
--- a/core/tests/test_apps.nem.hdnode.py
+++ b/core/tests/test_apps.nem.hdnode.py
@@ -9,6 +9,7 @@ if not utils.BITCOIN_ONLY:
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
+@unittest.skipUnless(utils.INTERNAL_MODEL == "T2T1", "only for T2T1")
class TestNemHDNode(unittest.TestCase):
def test_addresses(self):
# test vectors from https://raw.githubusercontent.com/NemProject/nem-test-vectors/master/1.test-keys.dat
@@ -320,5 +321,4 @@ class TestNemHDNode(unittest.TestCase):
if __name__ == "__main__":
- if utils.INTERNAL_MODEL == "T2T1":
- unittest.main()
+ unittest.main()
diff --git a/core/tests/test_trezor.io.fatfs.py b/core/tests/test_trezor.io.fatfs.py
index ec71c37f..5544ee82 100644
--- a/core/tests/test_trezor.io.fatfs.py
+++ b/core/tests/test_trezor.io.fatfs.py
@@ -5,6 +5,7 @@ if utils.USE_SD_CARD:
from trezorio import fatfs, sdcard
+@unittest.skipUnless(utils.USE_SD_CARD, "requires SD card")
class TestTrezorIoFatfs(unittest.TestCase):
def setUp(self):
sdcard.power_on()
@@ -127,6 +128,7 @@ class TestTrezorIoFatfsLfn(TestTrezorIoFatfs):
return f"reallylongdirname{suffix}"
+@unittest.skipUnless(utils.USE_SD_CARD, "requires SD card")
class TestTrezorIoFatfsMounting(unittest.TestCase):
MOUNTED_METHODS = [
("open", ("hello.txt", "w")),
@@ -210,6 +212,7 @@ class TestTrezorIoFatfsMounting(unittest.TestCase):
self.assertEqual(e.args[0], fatfs.FR_NOT_READY)
+@unittest.skipUnless(utils.USE_SD_CARD, "requires SD card")
class TestTrezorIoFatfsAndSdcard(unittest.TestCase):
def test_sd_power(self):
sdcard.power_off()
@@ -227,5 +230,4 @@ class TestTrezorIoFatfsAndSdcard(unittest.TestCase):
if __name__ == "__main__":
- if utils.USE_SD_CARD:
- unittest.main()
+ unittest.main()
diff --git a/core/tests/test_trezor.io.sdcard.py b/core/tests/test_trezor.io.sdcard.py
index 4aa6b977..88da69d0 100644
--- a/core/tests/test_trezor.io.sdcard.py
+++ b/core/tests/test_trezor.io.sdcard.py
@@ -4,6 +4,7 @@ from common import * # isort:skip
from trezor import io
+@unittest.skipUnless(utils.USE_SD_CARD, "requires SD card")
class TestTrezorIoSdcard(unittest.TestCase):
def test_start(self):
self.assertTrue(io.sdcard.is_present())
@@ -44,5 +45,4 @@ class TestTrezorIoSdcard(unittest.TestCase):
if __name__ == "__main__":
- if utils.USE_SD_CARD:
- unittest.main()
+ unittest.main()
diff --git a/core/tests/test_trezor.sdcard.py b/core/tests/test_trezor.sdcard.py
index 678c441d..bbb78cfb 100644
--- a/core/tests/test_trezor.sdcard.py
+++ b/core/tests/test_trezor.sdcard.py
@@ -7,6 +7,7 @@ if utils.USE_SD_CARD:
fatfs = io.fatfs
+@unittest.skipUnless(utils.USE_SD_CARD, "requires SD card")
class TestTrezorSdcard(unittest.TestCase):
def test_power(self):
# sdcard.capacity() will return 0 if the card is not powered,
@@ -90,5 +91,4 @@ class TestTrezorSdcard(unittest.TestCase):
if __name__ == "__main__":
- if utils.USE_SD_CARD:
- unittest.main()
+ unittest.main()
diff --git a/core/tests/test_trezor.wire.thp.crypto.py b/core/tests/test_trezor.wire.thp.crypto.py
index 56d046a3..4ae87dc1 100644
--- a/core/tests/test_trezor.wire.thp.crypto.py
+++ b/core/tests/test_trezor.wire.thp.crypto.py
@@ -78,7 +78,7 @@ class TestTrezorHostProtocolCrypto(unittest.TestCase):
]
def __init__(self):
- if __debug__:
+ if __debug__ and utils.USE_THP:
thp_common.suppress_debug_log()
super().__init__()
diff --git a/core/tests/test_trezor.wire.thp.writer.py b/core/tests/test_trezor.wire.thp.writer.py
index dc9824ee..d719fa80 100644
--- a/core/tests/test_trezor.wire.thp.writer.py
+++ b/core/tests/test_trezor.wire.thp.writer.py
@@ -74,7 +74,7 @@ class TestTrezorHostProtocolWriter(unittest.TestCase):
task.send(None)
def __init__(self):
- if __debug__:
+ if __debug__ and utils.USE_THP:
thp_common.suppress_debug_log()
super().__init__()
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.