1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-27 00:28:10 +00:00
trezor-firmware/core/docs/testing.md
2019-05-27 17:01:49 +02:00

2.2 KiB

Testing

Testing with python-trezor

Apart from the internal tests, Trezor core has a suite of integration tests in the python subdirectory. There are several ways to use that.

1. Running the full test suite

pipenv is a tool for making reproducible Python environments. Install it with:

sudo pip3 install pipenv

In the trezor-firmware checkout, install the environment:

pipenv sync

And run the automated tests:

pipenv run make -C core test_emu

2. Running tests manually

Install the pipenv environment as outlined above. Then switch to a shell inside the environment:

pipenv shell

If you want to test against the emulator, run it in a separate terminal from the core subdirectory:

PYOPT=0 ./emu.sh

Find the device address and export it as an environment variable. For the emulator, this is:

export TREZOR_PATH="udp:127.0.0.1:21324"

(You can find other devices with trezorctl list.)

Now you can run the test suite with pytest, either from python or core directory:

pytest

Or from anywhere else:

pytest --pyargs trezorlib.tests.device_tests  # this works from other locations

You can place your own tests in device_tests directory. See test style guide (TODO).

If you only want to run a particular test, pick it with -k <keyword> or -m <marker>:

pytest -k nem      # only runs tests that have "nem" in the name
pytest -m stellar  # only runs tests marked with @pytest.mark.stellar

If you want to see debugging information and protocol dumps, run with -v.

3. Using markers

When you're developing a new currency, you should mark all tests that belong to that currency. For example, if your currency is called NewCoin, your device tests should have the following marker:

@pytest.mark.newcoin

This marker must be registered in REGISTERED_MARKERS file.

If you wish to run a test only on TT, mark it with @pytest.mark.skip_t1. If the test should only run on T1, mark it with @pytest.mark.skip_t2. You must not use both on the same test.