From e2d45397d4f56a00e14baa7f79a09a633d3dff6e Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 21 Aug 2018 16:06:18 +0200 Subject: [PATCH] device_tests: smarter device selection skips bridge, dies somewhat more cleanly when no device found --- trezorlib/tests/device_tests/conftest.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/trezorlib/tests/device_tests/conftest.py b/trezorlib/tests/device_tests/conftest.py index 18b5189a2..a34580534 100644 --- a/trezorlib/tests/device_tests/conftest.py +++ b/trezorlib/tests/device_tests/conftest.py @@ -18,14 +18,23 @@ import functools import os import pytest -from trezorlib.transport import get_transport +from trezorlib.transport import get_transport, enumerate_devices from trezorlib.client import TrezorClient, TrezorClientDebugLink from trezorlib import log, coins +TREZOR_VERSION = None + def get_device(): path = os.environ.get("TREZOR_PATH") - return get_transport(path) + if path: + return get_transport(path) + else: + devices = enumerate_devices() + for device in devices: + if hasattr(device, "find_debug"): + return device + raise RuntimeError("No debuggable device found") def device_version(): @@ -39,9 +48,6 @@ def device_version(): return 1 -TREZOR_VERSION = device_version() - - @pytest.fixture(scope="function") def client(): wirelink = get_device() @@ -86,6 +92,9 @@ def setup_client(mnemonic=None, pin="", passphrase=False): def pytest_configure(config): + global TREZOR_VERSION + TREZOR_VERSION = device_version() + if config.getoption("verbose"): log.enable_debug_output()