mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-08-05 13:26:57 +00:00
test(core): don't stop tests in case of communication failure
[no changelog]
This commit is contained in:
parent
e3efe00b3a
commit
29b40e4d7c
@ -18,6 +18,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
import typing as t
|
import typing as t
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -54,6 +55,8 @@ if t.TYPE_CHECKING:
|
|||||||
HERE = Path(__file__).resolve().parent
|
HERE = Path(__file__).resolve().parent
|
||||||
CORE = HERE.parent / "core"
|
CORE = HERE.parent / "core"
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
# So that we see details of failed asserts from this module
|
# So that we see details of failed asserts from this module
|
||||||
pytest.register_assert_rewrite("tests.common")
|
pytest.register_assert_rewrite("tests.common")
|
||||||
pytest.register_assert_rewrite("tests.input_flows")
|
pytest.register_assert_rewrite("tests.input_flows")
|
||||||
@ -238,6 +241,22 @@ class ModelsFilter:
|
|||||||
return selected_models
|
return selected_models
|
||||||
|
|
||||||
|
|
||||||
|
def _initialize_with_retries(
|
||||||
|
request: pytest.FixtureRequest, raw_client: Client
|
||||||
|
) -> None:
|
||||||
|
"""Stop the test session if the error reproduces a few times."""
|
||||||
|
for _ in range(5):
|
||||||
|
try:
|
||||||
|
raw_client.sync_responses()
|
||||||
|
raw_client.init_device()
|
||||||
|
return
|
||||||
|
except Exception:
|
||||||
|
LOG.warning("Failed to initialize client", exc_info=True)
|
||||||
|
time.sleep(1)
|
||||||
|
request.session.shouldstop = "Failed to communicate with Trezor"
|
||||||
|
pytest.fail("Failed to communicate with Trezor")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def client(
|
def client(
|
||||||
request: pytest.FixtureRequest, _raw_client: Client
|
request: pytest.FixtureRequest, _raw_client: Client
|
||||||
@ -288,12 +307,7 @@ def client(
|
|||||||
_raw_client.reset_debug_features()
|
_raw_client.reset_debug_features()
|
||||||
_raw_client.open()
|
_raw_client.open()
|
||||||
try:
|
try:
|
||||||
try:
|
_initialize_with_retries(request, _raw_client)
|
||||||
_raw_client.sync_responses()
|
|
||||||
_raw_client.init_device()
|
|
||||||
except Exception:
|
|
||||||
request.session.shouldstop = "Failed to communicate with Trezor"
|
|
||||||
pytest.fail("Failed to communicate with Trezor")
|
|
||||||
|
|
||||||
# Resetting all the debug events to not be influenced by previous test
|
# Resetting all the debug events to not be influenced by previous test
|
||||||
_raw_client.debug.reset_debug_events()
|
_raw_client.debug.reset_debug_events()
|
||||||
|
Loading…
Reference in New Issue
Block a user