mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-05-06 17:09:11 +00:00
test(core): close _raw_client
in case client()
fixture fails
[no changelog]
This commit is contained in:
parent
a91d18ba2c
commit
f436bcd6fa
@ -283,73 +283,74 @@ def client(
|
|||||||
_raw_client.reset_debug_features()
|
_raw_client.reset_debug_features()
|
||||||
_raw_client.open()
|
_raw_client.open()
|
||||||
try:
|
try:
|
||||||
_raw_client.sync_responses()
|
try:
|
||||||
_raw_client.init_device()
|
_raw_client.sync_responses()
|
||||||
except Exception:
|
_raw_client.init_device()
|
||||||
request.session.shouldstop = "Failed to communicate with Trezor"
|
except Exception:
|
||||||
pytest.fail("Failed to communicate with Trezor")
|
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()
|
||||||
|
|
||||||
if test_ui:
|
if test_ui:
|
||||||
# we need to reseed before the wipe
|
# we need to reseed before the wipe
|
||||||
_raw_client.debug.reseed(0)
|
_raw_client.debug.reseed(0)
|
||||||
|
|
||||||
if sd_marker:
|
if sd_marker:
|
||||||
should_format = sd_marker.kwargs.get("formatted", True)
|
should_format = sd_marker.kwargs.get("formatted", True)
|
||||||
_raw_client.debug.erase_sd_card(format=should_format)
|
_raw_client.debug.erase_sd_card(format=should_format)
|
||||||
|
|
||||||
wipe_device(_raw_client)
|
wipe_device(_raw_client)
|
||||||
|
|
||||||
# Load language again, as it got erased in wipe
|
# Load language again, as it got erased in wipe
|
||||||
if _raw_client.model is not models.T1B1:
|
if _raw_client.model is not models.T1B1:
|
||||||
lang = request.session.config.getoption("lang") or "en"
|
lang = request.session.config.getoption("lang") or "en"
|
||||||
assert isinstance(lang, str)
|
assert isinstance(lang, str)
|
||||||
translations.set_language(_raw_client, lang)
|
translations.set_language(_raw_client, lang)
|
||||||
|
|
||||||
setup_params = dict(
|
setup_params = dict(
|
||||||
uninitialized=False,
|
uninitialized=False,
|
||||||
mnemonic=" ".join(["all"] * 12),
|
mnemonic=" ".join(["all"] * 12),
|
||||||
pin=None,
|
pin=None,
|
||||||
passphrase=False,
|
passphrase=False,
|
||||||
needs_backup=False,
|
needs_backup=False,
|
||||||
no_backup=False,
|
no_backup=False,
|
||||||
)
|
|
||||||
|
|
||||||
marker = request.node.get_closest_marker("setup_client")
|
|
||||||
if marker:
|
|
||||||
setup_params.update(marker.kwargs)
|
|
||||||
|
|
||||||
use_passphrase = setup_params["passphrase"] is True or isinstance(
|
|
||||||
setup_params["passphrase"], str
|
|
||||||
)
|
|
||||||
|
|
||||||
if not setup_params["uninitialized"]:
|
|
||||||
debuglink.load_device(
|
|
||||||
_raw_client,
|
|
||||||
mnemonic=setup_params["mnemonic"], # type: ignore
|
|
||||||
pin=setup_params["pin"], # type: ignore
|
|
||||||
passphrase_protection=use_passphrase,
|
|
||||||
label="test",
|
|
||||||
needs_backup=setup_params["needs_backup"], # type: ignore
|
|
||||||
no_backup=setup_params["no_backup"], # type: ignore
|
|
||||||
_skip_init_device=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if request.node.get_closest_marker("experimental"):
|
marker = request.node.get_closest_marker("setup_client")
|
||||||
apply_settings(_raw_client, experimental_features=True)
|
if marker:
|
||||||
|
setup_params.update(marker.kwargs)
|
||||||
|
|
||||||
if use_passphrase and isinstance(setup_params["passphrase"], str):
|
use_passphrase = setup_params["passphrase"] is True or isinstance(
|
||||||
_raw_client.use_passphrase(setup_params["passphrase"])
|
setup_params["passphrase"], str
|
||||||
|
)
|
||||||
|
|
||||||
_raw_client.lock(_refresh_features=False)
|
if not setup_params["uninitialized"]:
|
||||||
_raw_client.init_device(new_session=True)
|
debuglink.load_device(
|
||||||
|
_raw_client,
|
||||||
|
mnemonic=setup_params["mnemonic"], # type: ignore
|
||||||
|
pin=setup_params["pin"], # type: ignore
|
||||||
|
passphrase_protection=use_passphrase,
|
||||||
|
label="test",
|
||||||
|
needs_backup=setup_params["needs_backup"], # type: ignore
|
||||||
|
no_backup=setup_params["no_backup"], # type: ignore
|
||||||
|
_skip_init_device=True,
|
||||||
|
)
|
||||||
|
|
||||||
with ui_tests.screen_recording(_raw_client, request):
|
if request.node.get_closest_marker("experimental"):
|
||||||
yield _raw_client
|
apply_settings(_raw_client, experimental_features=True)
|
||||||
|
|
||||||
_raw_client.close()
|
if use_passphrase and isinstance(setup_params["passphrase"], str):
|
||||||
|
_raw_client.use_passphrase(setup_params["passphrase"])
|
||||||
|
|
||||||
|
_raw_client.lock(_refresh_features=False)
|
||||||
|
_raw_client.init_device(new_session=True)
|
||||||
|
|
||||||
|
with ui_tests.screen_recording(_raw_client, request):
|
||||||
|
yield _raw_client
|
||||||
|
finally:
|
||||||
|
_raw_client.close()
|
||||||
|
|
||||||
|
|
||||||
def _is_main_runner(session_or_request: pytest.Session | pytest.FixtureRequest) -> bool:
|
def _is_main_runner(session_or_request: pytest.Session | pytest.FixtureRequest) -> bool:
|
||||||
|
Loading…
Reference in New Issue
Block a user