1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 02:58:57 +00:00

fix(tests): python >=3.11 compatibility for identifiers

Python 3.11 changed IntEnum.__str__ to return the number instead of the
enum value name. This breaks fixtures.json because pytest uses
str(value) to generate the test identifier names, and in a lot of places
our identifiers use the enum values.

This override of `_idval_from_value` explicitly generates a name from
the IntEnum instead of using the __str__ implementation.
This commit is contained in:
matejcik 2024-07-30 11:28:34 +02:00 committed by M1nd3r
parent 8a9a965a9f
commit 5dc8998a0b

View File

@ -17,11 +17,13 @@
from __future__ import annotations
import os
from enum import IntEnum
from pathlib import Path
from typing import TYPE_CHECKING, Generator, Iterator
from typing import TYPE_CHECKING, Any, Generator, Iterator
import pytest
import xdist
from _pytest.python import IdMaker
from _pytest.reports import TestReport
from trezorlib import debuglink, log, models
@ -417,6 +419,16 @@ def pytest_configure(config: "Config") -> None:
if config.getoption("verbose"):
log.enable_debug_output()
idval_orig = IdMaker._idval_from_value
def idval_from_value(self: IdMaker, val: object) -> str | None:
if isinstance(val, IntEnum):
return f"{type(val).__name__}.{val.name}"
return idval_orig(self, val)
IdMaker._idval_from_value = idval_from_value
def pytest_runtest_setup(item: pytest.Item) -> None:
"""Called for each test item (class, individual tests).