1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-04-20 17:19:01 +00:00

chore(test): add invalidate_client marker

This commit is contained in:
M1nd3r 2025-03-24 11:14:44 +01:00
parent d387253377
commit 4bcd277a72
2 changed files with 25 additions and 5 deletions

View File

@ -60,7 +60,7 @@ if t.TYPE_CHECKING:
HERE = Path(__file__).resolve().parent
CORE = HERE.parent / "core"
LOG = logging.getLogger(__name__)
LOCK_TIME = 0.2
# So that we see details of failed asserts from this module
pytest.register_assert_rewrite("tests.common")
@ -344,7 +344,16 @@ def _client_unlocked(
while True:
try:
if _raw_client.is_invalidated:
_raw_client = _raw_client.get_new_client()
try:
_raw_client = _raw_client.get_new_client()
except Exception as e:
import logging
LOG = logging.getLogger(__name__)
LOG.error(f"Failed to re-create a client: {e}")
sleep(LOCK_TIME)
_raw_client = _get_raw_client(request)
session = _raw_client.get_seedless_session()
wipe_device(session)
sleep(1.5) # Makes tests more stable (wait for wipe to finish)
@ -406,8 +415,15 @@ def client(
request: pytest.FixtureRequest, _client_unlocked: Client
) -> t.Generator[Client, None, None]:
_client_unlocked.lock()
with ui_tests.screen_recording(_client_unlocked, request):
yield _client_unlocked
if bool(request.node.get_closest_marker("invalidate_client")):
with ui_tests.screen_recording(_client_unlocked, request):
try:
yield _client_unlocked
finally:
_client_unlocked.invalidate()
else:
with ui_tests.screen_recording(_client_unlocked, request):
yield _client_unlocked
@pytest.fixture(scope="function")
@ -554,6 +570,10 @@ def pytest_configure(config: "Config") -> None:
"markers",
"uninitialized_session: use uninitialized session instance",
)
config.addinivalue_line(
"markers",
"invalidate_client: invalidate client after test",
)
with open(os.path.join(os.path.dirname(__file__), "REGISTERED_MARKERS")) as f:
for line in f:
config.addinivalue_line("markers", line.strip())

View File

@ -7,7 +7,7 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client
from .connect import prepare_protocol_for_handshake
pytestmark = [pytest.mark.protocol("protocol_v2")]
pytestmark = [pytest.mark.protocol("protocol_v2"), pytest.mark.invalidate_client]
def test_allocate_channel(client: Client) -> None: