mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-04-28 21:19:03 +00:00
chore(test): add invalidate_client marker
This commit is contained in:
parent
e8683bfcd7
commit
c96e0590a2
@ -60,7 +60,7 @@ 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__)
|
LOCK_TIME = 0.2
|
||||||
|
|
||||||
# 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")
|
||||||
@ -343,7 +343,16 @@ def _client_unlocked(
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if _raw_client.is_invalidated:
|
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()
|
session = _raw_client.get_seedless_session()
|
||||||
wipe_device(session)
|
wipe_device(session)
|
||||||
sleep(1.5) # Makes tests more stable (wait for wipe to finish)
|
sleep(1.5) # Makes tests more stable (wait for wipe to finish)
|
||||||
@ -405,8 +414,15 @@ def client(
|
|||||||
request: pytest.FixtureRequest, _client_unlocked: Client
|
request: pytest.FixtureRequest, _client_unlocked: Client
|
||||||
) -> t.Generator[Client, None, None]:
|
) -> t.Generator[Client, None, None]:
|
||||||
_client_unlocked.lock()
|
_client_unlocked.lock()
|
||||||
with ui_tests.screen_recording(_client_unlocked, request):
|
if bool(request.node.get_closest_marker("invalidate_client")):
|
||||||
yield _client_unlocked
|
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")
|
@pytest.fixture(scope="function")
|
||||||
@ -553,6 +569,10 @@ def pytest_configure(config: "Config") -> None:
|
|||||||
"markers",
|
"markers",
|
||||||
"uninitialized_session: use uninitialized session instance",
|
"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:
|
with open(os.path.join(os.path.dirname(__file__), "REGISTERED_MARKERS")) as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
config.addinivalue_line("markers", line.strip())
|
config.addinivalue_line("markers", line.strip())
|
||||||
|
@ -7,7 +7,7 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client
|
|||||||
|
|
||||||
from .connect import prepare_protocol_for_handshake
|
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:
|
def test_allocate_channel(client: Client) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user