Note: You need Uv, as mentioned in the core's documentation section.
In the trezor-firmware checkout, in the root of the monorepo, install the environment:
uv syncAnd run the tests:
uv run make -C core test_emu_uiInstall the uv environment as outlined above. Then activate the environment:
source .venv/bin/activateIf you want to test against the emulator, run it with disabled animation in a separate terminal:
./core/emu.py -aNow you can run the test suite with pytest from the root directory:
pytest tests/device_tests --ui=testIf you wish to check that all test cases in fixtures.json were used set the --ui-check-missing flag. Of course this is meaningful only if you run the tests on the whole device_tests folder.
pytest tests/device_tests --ui=test --ui-check-missingShort version:
uv run make -C core test_emu_ui_recordLong version:
The --ui pytest argument has two options:
- record: Create screenshots and calculate theirs hash for each test. The screenshots are gitignored, but the hash is included in git.
- test: Create screenshots, calculate theirs hash and test the hash against the one stored in git.
If you want to make a change in the UI you simply run --ui=record. An easy way
to proceed is to run --ui=test at first, see what tests fail (see the Reports section below),
decide if those changes are the ones you expected and then finally run the --ui=record
and commit the new hashes.
Also here we provide an option to check the fixtures.json file. Use --ui-check-missing flag again to make sure there are no extra fixtures in the file:
pytest tests/device_tests --ui=record --ui-check-missingEach --ui=test creates a clear report which tests passed and which failed.
The index file is stored in tests/ui_tests/reports/test/index.html.
The script tests/show_results.py starts a local HTTP server that serves this page --
this is necessary for access to browser local storage, which enables a simple reviewer
UI.
On CI this report is published as an artifact.
If needed, you can use python3 -m tests.ui_tests to regenerate the report from local
recorded screens.
In the ui tests folder you will also find a Python script report_master_diff.py, which
creates a report where you find which tests were altered, added, or removed relative to
master. This useful for Pull Requests.
This report is available as an artifact on CI as well. You can find it by
visiting the "unix ui changes" job in your pipeline - browse the
artifacts and open master_diff/index.html.