From a0d7a6a6678a72fa56fc760a30485de8e074a3f3 Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 27 May 2019 15:42:41 +0200 Subject: [PATCH] python: more consistent handling of markers in device_tests also better behavior when no Trezor device is present --- core/pytest.ini | 21 ++------------- .../tests/device_tests/REGISTERED_MARKERS | 14 ++++++++++ .../trezorlib/tests/device_tests/conftest.py | 27 ++++++++++++------- .../device_tests/test_msg_applysettings.py | 6 ++--- setup.cfg | 19 ++----------- 5 files changed, 38 insertions(+), 49 deletions(-) create mode 100644 python/trezorlib/tests/device_tests/REGISTERED_MARKERS diff --git a/core/pytest.ini b/core/pytest.ini index f7b4a230f..985b7cdc7 100644 --- a/core/pytest.ini +++ b/core/pytest.ini @@ -1,20 +1,3 @@ [pytest] -addopts = --pyargs trezorlib.tests.device_tests - -markers = - capricoin - cardano - decred - eos - ethereum - komodo - lisk - monero - nem - ontology - ripple - skip_t1 - skip_t2 - stellar - tezos - zcash +addopts = --strict --pyargs trezorlib.tests.device_tests +xfail_strict = true diff --git a/python/trezorlib/tests/device_tests/REGISTERED_MARKERS b/python/trezorlib/tests/device_tests/REGISTERED_MARKERS new file mode 100644 index 000000000..41ece6798 --- /dev/null +++ b/python/trezorlib/tests/device_tests/REGISTERED_MARKERS @@ -0,0 +1,14 @@ +capricoin +cardano +decred +eos +ethereum +komodo +lisk +monero +nem +ontology +ripple +stellar +tezos +zcash diff --git a/python/trezorlib/tests/device_tests/conftest.py b/python/trezorlib/tests/device_tests/conftest.py index d10f847e4..ac51dbc32 100644 --- a/python/trezorlib/tests/device_tests/conftest.py +++ b/python/trezorlib/tests/device_tests/conftest.py @@ -91,21 +91,25 @@ def setup_client(mnemonic=None, pin="", passphrase=False): def pytest_configure(config): + # try to figure out trezor version global TREZOR_VERSION - TREZOR_VERSION = device_version() - + try: + TREZOR_VERSION = device_version() + except Exception: + pass + + # register known markers + config.addinivalue_line("markers", "skip_t1: skip the test on Trezor One") + config.addinivalue_line("markers", "skip_t2: skip the test on Trezor T") + with open(os.path.join(os.path.dirname(__file__), "REGISTERED_MARKERS")) as f: + for line in f: + config.addinivalue_line("markers", line.strip()) + + # enable debug if config.getoption("verbose"): log.enable_debug_output() -def pytest_addoption(parser): - parser.addoption( - "--interactive", - action="store_true", - help="Wait for user to do interaction manually", - ) - - def pytest_runtest_setup(item): """ Called for each test item (class, individual tests). @@ -114,6 +118,9 @@ def pytest_runtest_setup(item): * 'skip_t2' tests are skipped on T2 and 'skip_t1' tests are skipped on T1. * no test should have both skips at the same time """ + if TREZOR_VERSION is None: + pytest.fail("No debuggable Trezor is available") + if item.get_closest_marker("skip_t1") and item.get_closest_marker("skip_t2"): pytest.fail("Don't skip tests for both trezors!") diff --git a/python/trezorlib/tests/device_tests/test_msg_applysettings.py b/python/trezorlib/tests/device_tests/test_msg_applysettings.py index 4ae177632..bfe070f50 100644 --- a/python/trezorlib/tests/device_tests/test_msg_applysettings.py +++ b/python/trezorlib/tests/device_tests/test_msg_applysettings.py @@ -26,10 +26,10 @@ from .conftest import TREZOR_VERSION EXPECTED_RESPONSES_NOPIN = [proto.ButtonRequest(), proto.Success(), proto.Features()] EXPECTED_RESPONSES_PIN = [proto.PinMatrixRequest()] + EXPECTED_RESPONSES_NOPIN -if TREZOR_VERSION >= 2: - EXPECTED_RESPONSES = EXPECTED_RESPONSES_NOPIN -else: +if TREZOR_VERSION == 1: EXPECTED_RESPONSES = EXPECTED_RESPONSES_PIN +else: + EXPECTED_RESPONSES = EXPECTED_RESPONSES_NOPIN class TestMsgApplysettings(TrezorTest): diff --git a/setup.cfg b/setup.cfg index fcad4e1a5..0a6d31e97 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,20 +29,5 @@ known_standard_library = micropython,ubinascii,ustruct,uctypes,utime,utimeq,trez known_third_party = curve25519,ecdsa,hypothesis [tool:pytest] -markers = - capricoin - cardano - decred - eos - ethereum - komodo - lisk - monero - nem - ontology - ripple - skip_t1: skip the test on Trezor One. - skip_t2: skip the test on Trezor Model T. - stellar - tezos - zcash +addopts = --strict +xfail_strict = true