1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-06-27 10:22:34 +00:00

chore(python): replace 'pytest-rerunfailures' with 'pytest-retry'

[no changelog]
This commit is contained in:
Roman Zeyde 2025-03-26 11:17:04 +02:00 committed by Roman Zeyde
parent 3a24945de9
commit f1d3f835b8
7 changed files with 26 additions and 17 deletions

18
poetry.lock generated
View File

@ -1593,20 +1593,22 @@ files = [
pytest = ">=3.0.0" pytest = ">=3.0.0"
[[package]] [[package]]
name = "pytest-rerunfailures" name = "pytest-retry"
version = "15.0" version = "1.7.0"
description = "pytest plugin to re-run tests to eliminate flaky failures" description = "Adds the ability to retry flaky tests in CI environments"
optional = false optional = false
python-versions = ">=3.9" python-versions = ">=3.9"
groups = ["main"] groups = ["main"]
files = [ files = [
{file = "pytest-rerunfailures-15.0.tar.gz", hash = "sha256:2d9ac7baf59f4c13ac730b47f6fa80e755d1ba0581da45ce30b72fb3542b4474"}, {file = "pytest_retry-1.7.0-py3-none-any.whl", hash = "sha256:a2dac85b79a4e2375943f1429479c65beb6c69553e7dae6b8332be47a60954f4"},
{file = "pytest_rerunfailures-15.0-py3-none-any.whl", hash = "sha256:dd150c4795c229ef44320adc9a0c0532c51b78bb7a6843a8c53556b9a611df1a"}, {file = "pytest_retry-1.7.0.tar.gz", hash = "sha256:f8d52339f01e949df47c11ba9ee8d5b362f5824dff580d3870ec9ae0057df80f"},
] ]
[package.dependencies] [package.dependencies]
packaging = ">=17.1" pytest = ">=7.0.0"
pytest = ">=7.4,<8.2.2 || >8.2.2"
[package.extras]
dev = ["black", "flake8", "isort", "mypy"]
[[package]] [[package]]
name = "pytest-timeout" name = "pytest-timeout"
@ -2340,4 +2342,4 @@ test = ["big-O", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more-it
[metadata] [metadata]
lock-version = "2.1" lock-version = "2.1"
python-versions = "^3.9" python-versions = "^3.9"
content-hash = "3d8597dbd91d37eabc20ce7e19f5996cda93243fcfbcd93fba73e9abd7b46373" content-hash = "3cf7446762b2697275d563511071e6368edafb8c86eeb88a402bbe7bfb9ba6ac"

View File

@ -77,7 +77,7 @@ trezor-pylint-plugin = {path = "./tools/trezor-pylint-plugin", develop = true}
trezor-core-tools = {path = "./core/tools", develop = true} trezor-core-tools = {path = "./core/tools", develop = true}
flake8-annotations = "^3.1.1" flake8-annotations = "^3.1.1"
pyelftools = "^0.32" pyelftools = "^0.32"
pytest-rerunfailures = "^15.0" pytest-retry = "^1.7.0"
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
scan-build = "*" scan-build = "*"

View File

@ -35,6 +35,10 @@ LOG = logging.getLogger(__name__)
_DEFAULT_READ_TIMEOUT: float | None = None _DEFAULT_READ_TIMEOUT: float | None = None
class UnexpectedMagic(RuntimeError):
pass
class Handle(StructuralType): class Handle(StructuralType):
"""PEP 544 structural type for Handle functionality. """PEP 544 structural type for Handle functionality.
(called a "Protocol" in the proposed PEP, name which is impractical here) (called a "Protocol" in the proposed PEP, name which is impractical here)
@ -163,7 +167,7 @@ class ProtocolV1(Protocol):
def read_first(self, timeout: float | None = None) -> tuple[int, int, bytes]: def read_first(self, timeout: float | None = None) -> tuple[int, int, bytes]:
chunk = self.handle.read_chunk(timeout=timeout) chunk = self.handle.read_chunk(timeout=timeout)
if chunk[:3] != b"?##": if chunk[:3] != b"?##":
raise RuntimeError(f"Unexpected magic characters: {chunk.hex()}") raise UnexpectedMagic(chunk.hex())
try: try:
msg_type, datalen = struct.unpack(">HL", chunk[3 : 3 + self.HEADER_LEN]) msg_type, datalen = struct.unpack(">HL", chunk[3 : 3 + self.HEADER_LEN])
except Exception: except Exception:
@ -175,5 +179,5 @@ class ProtocolV1(Protocol):
def read_next(self, timeout: float | None = None) -> bytes: def read_next(self, timeout: float | None = None) -> bytes:
chunk = self.handle.read_chunk(timeout=timeout) chunk = self.handle.read_chunk(timeout=timeout)
if chunk[:1] != b"?": if chunk[:1] != b"?":
raise RuntimeError(f"Unexpected magic characters: {chunk.hex()}") raise UnexpectedMagic(chunk.hex())
return chunk[1:] return chunk[1:]

View File

@ -40,9 +40,8 @@ addopts =
-rfER -rfER
--strict-markers --strict-markers
--random-order --random-order
--only-rerun='RuntimeError: Unexpected magic characters: 3f' --retries=5
--only-rerun='Timeout: Timeout reading [A-Za-z]+ packet' --retry-delay=1
--reruns=5
testpaths = tests crypto storage python/tests testpaths = tests crypto storage python/tests
xfail_strict = true xfail_strict = true
junit_family = xunit2 junit_family = xunit2

View File

@ -31,7 +31,7 @@ from trezorlib import debuglink, log, models
from trezorlib.debuglink import TrezorClientDebugLink as Client from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.device import apply_settings from trezorlib.device import apply_settings
from trezorlib.device import wipe as wipe_device from trezorlib.device import wipe as wipe_device
from trezorlib.transport import enumerate_devices, get_transport, protocol from trezorlib.transport import Timeout, enumerate_devices, get_transport, protocol
# register rewrites before importing from local package # register rewrites before importing from local package
# so that we see details of failed asserts from this module # so that we see details of failed asserts from this module
@ -505,6 +505,10 @@ def pytest_runtest_setup(item: pytest.Item) -> None:
pytest.skip("Skipping altcoin test") pytest.skip("Skipping altcoin test")
def pytest_set_filtered_exceptions():
return (Timeout, protocol.UnexpectedMagic)
@pytest.hookimpl(tryfirst=True, hookwrapper=True) @pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item: pytest.Item, call) -> t.Generator: def pytest_runtest_makereport(item: pytest.Item, call) -> t.Generator:
# Make test results available in fixtures. # Make test results available in fixtures.

View File

@ -25,7 +25,7 @@ from trezorlib.tools import H_
pytestmark = [ pytestmark = [
pytest.mark.models("legacy"), pytest.mark.models("legacy"),
pytest.mark.flaky(reruns=5), pytest.mark.flaky(retries=5),
] ]

View File

@ -88,7 +88,7 @@ def test_busy_expiry_core(client: Client):
_assert_busy(client, False) _assert_busy(client, False)
@pytest.mark.flaky(reruns=5) @pytest.mark.flaky(retries=5)
@pytest.mark.models("legacy") @pytest.mark.models("legacy")
def test_busy_expiry_legacy(client: Client): def test_busy_expiry_legacy(client: Client):
_assert_busy(client, False) _assert_busy(client, False)