This project provides a test framework supporting both mock tests (no hardware required) and hardware tests (using a STeaMi board).
All tests are executed using pytest.
make setupThis installs all dependencies (ruff, pytest, pyyaml via pip + git hooks via npm).
All test commands are available via make. Run make help to see the full list.
make test-mockExecutes tests using simulated registers. No hardware is required.
make test-hardwareRuns all tests on a connected STeaMi board (default port: /dev/ttyACM0).
make test-boardmake test-sensorsmake test-hts221Per-scenario targets are generated automatically from tests/scenarios/*.yaml. Any YAML file added to that directory creates a corresponding make test-<name> target.
make test-allmake test-hardware PORT=/dev/ttyACM1Test reports can be generated in Markdown format.
# Timestamped report
python -m pytest tests/ -v --port /dev/ttyACM0 --report auto
# Named report
python -m pytest tests/ -v --port /dev/ttyACM0 --report v1.0-validationReports are saved in the reports/ directory and include:
- A global summary
- A detailed report per driver
Create a YAML scenario file in tests/scenarios/<driver>.yaml:
Each scenario describes:
- Initial register state
- Actions performed
- Expected results
Example structure:
driver: hts221
driver_class: HTS221
i2c_address: 0x5F
i2c:
id: 1
mock_registers:
0x0F: 0xBC
tests:
- name: "Verify device ID"
action: read_register
register: 0x0F
expect: 0xBC
mode: [mock, hardware]
- name: "Temperature in plausible range"
action: call
method: temperature
expect_range: [10.0, 45.0]
mode: [hardware]The test runner automatically discovers new YAML files.
The Makefile generates a make test-<name> target for each YAML scenario. The target name comes from:
- Driver scenarios: the
driverfield in the YAML (e.g.driver: wsen-hids→make test-wsen-hids) - Board scenarios: the filename stem (e.g.
board_buttons.yaml→make test-board_buttons)
Important: for board scenarios (type: board), the name field in the YAML must match the filename (without .yaml). If they diverge, make test-<name> will not find any tests. For driver scenarios, the driver field is used and the filename can differ (e.g. wsen_hids.yaml with driver: wsen-hids works correctly).
- Provide at least mock tests for every driver
- Add hardware tests when possible
- Ensure all tests pass before submitting a Pull Request