test(core): check Optiga presence once per session
What changed, and why it matters
This commit is a minor internal test-framework cleanup. It moves a single check for whether the device under test has an Optiga security chip from one place to another, computing it once per test session instead of repeatedly. There is no change to the firmware that runs on a real Trezor device, no user-facing behavior change, and no security fix or vulnerability.
No security action required. Treat as ordinary test-code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors test infrastructure in trezorlib/debuglink.py and tests/conftest.py. It adds a has_optiga boolean attribute to TrezorTestContext, populated from features.optiga_sec, and replaces an inline features.optiga_sec is not None check in _prepared_test_ctx with a read of that attribute. Two non-functional comments were added. No production firmware code is modified.
Changed components
python/src/trezorlib/debuglink.pytests/conftest.pyInspect captured patch +8 / −3
diff --git a/python/src/trezorlib/debuglink.py b/python/src/trezorlib/debuglink.py
index 2bb934c9..4bf6df1e 100644
--- a/python/src/trezorlib/debuglink.py
+++ b/python/src/trezorlib/debuglink.py
@@ -1392,6 +1392,8 @@ class TrezorTestContext:
self.debug.model = self.model = self.client.model
self.layout_type = self.debug.layout_type
self.is_emulator = self.features.fw_vendor == "EMULATOR"
+ # Optiga's presence is detected from the presence of its security counter.
+ self.has_optiga = self.features.optiga_sec is not None
def _get_client(self) -> client.TrezorClient:
if self.protocol_version is ProtocolVersion.V1:
diff --git a/tests/conftest.py b/tests/conftest.py
index e8b75db4..56797503 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -386,6 +386,7 @@ def _prepared_test_ctx(
@pytest.mark.experimental
"""
+ # Early exit, if the test cannot be run:
models_filter = ModelsFilter(request.node)
if _raw_test_ctx.model not in models_filter:
pytest.skip(f"Skipping test for model {_raw_test_ctx.model.internal_name}")
@@ -397,9 +398,10 @@ def _prepared_test_ctx(
if request.node.get_closest_marker("altcoin") and is_btc_only:
pytest.skip("Skipping altcoin test")
- # Optiga's presence is detected from the presence of its security counter.
- has_optiga = _raw_test_ctx.features.optiga_sec is not None
- if request.node.get_closest_marker("xfail_if_no_optiga") and not has_optiga:
+ if (
+ request.node.get_closest_marker("xfail_if_no_optiga")
+ and not _raw_test_ctx.has_optiga
+ ):
pytest.xfail("Optiga is not available on this device.")
_check_protocol(request, _raw_test_ctx)
@@ -414,6 +416,7 @@ def _prepared_test_ctx(
fail_on_gc_leak = not request.config.getoption("ignore_gc_leak")
+ # First, make sure the device is responsive:
_raw_test_ctx.reset_debug_features()
try:
_raw_test_ctx.sync_responses()
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.