From b07ed98ba409cdbf112347bc89ba71fbe92e3e84 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Wed, 19 Mar 2025 08:56:19 +0200 Subject: [PATCH] test(core): allow saving verbose log into a file [no changelog] --- .github/workflows/core-hw.yml | 6 ++++-- tests/conftest.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/core-hw.yml b/.github/workflows/core-hw.yml index ed226272d9..df3b0c2e14 100644 --- a/.github/workflows/core-hw.yml +++ b/.github/workflows/core-hw.yml @@ -55,13 +55,15 @@ jobs: - run: | # log serial console to file; sleep is used because tio needs stdin that is not /dev/null nix-shell --arg hardwareTest true --run "sleep 8h | tio --timestamp --no-autoconnect /dev/ttyTREZOR &> trezor.log" & - nix-shell --run "poetry run pytest -v tests/device_tests $TESTOPTS" + nix-shell --run "poetry run pytest -v --verbose-log-file pytest.log tests/device_tests $TESTOPTS" - run: tail -n50 trezor.log || true if: failure() - uses: actions/upload-artifact@v4 with: name: core-hardware-${{ matrix.model }}-${{ matrix.coins }} - path: trezor.log + path: | + trezor.log + pytest.log retention-days: 7 if: always() diff --git a/tests/conftest.py b/tests/conftest.py index 46a0f25eb6..b662327fb7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,6 +16,7 @@ from __future__ import annotations +import logging import os import typing as t from enum import IntEnum @@ -441,6 +442,12 @@ def pytest_addoption(parser: "Parser") -> None: choices=translations.LANGUAGES, help="Run tests with a specified language: 'en' is the default", ) + parser.addoption( + "--verbose-log-file", + action="store", + default=None, + help="File path for verbose logging", + ) def pytest_configure(config: "Config") -> None: @@ -469,6 +476,11 @@ def pytest_configure(config: "Config") -> None: if verbosity: log.enable_debug_output(verbosity) + verbose_log_file = config.getoption("verbose_log_file") + if verbose_log_file: + handler = logging.FileHandler(verbose_log_file) + log.enable_debug_output(verbosity, handler) + idval_orig = IdMaker._idval_from_value def idval_from_value(self: IdMaker, val: object) -> str | None: