reference
pytest plugin
Installing hardlabs-sdk registers a pytest plugin. It adds the fixtures, the marker and the command-line options below. It signs in only when a test asks for the board.
A failing test's report includes the console's last 40 lines and Board.problems.
hardlabs_boardfixture · session
The simulated board, booted once for the test session and stopped at its end.
hardlabs_board -> BoardIt boots the board --hardlabs-sim names with --hardlabs-firmware, or the board's own firmware when none is given. A test marked hardlabs_fresh gets it restarted first.
Usage
def test_alarm(hardlabs_board):
hardlabs_board.do("temperature-sensor-mcp9808.overheat-75-c")
hardlabs_board.wait_for("ALARM", within=5)hardlabs_serialfixture · session
Opens one of the board's serial ports for the test session, as Board.serial does.
hardlabs_serial(port="console", *, pty=False) -> SerialBridgeCalling it again with the same arguments returns the same SerialBridge, so every test sees one address. The address survives restarts.
Usage
@pytest.fixture(scope="session", autouse=True)
def setup(hardlabs_serial):
set_context(hardlabs_serial("rs485").url)hardlabs_freshmarker
Boot the simulated board afresh (memory chips too) before this test.
@pytest.mark.hardlabs_freshCommand-line options
| Option | Description | Environment variable |
|---|---|---|
| --hardlabs-sim | The simulation to test against: owner/project[@version]. | HARDLABS_SIM |
| --hardlabs-firmware | Firmware to boot: an ELF, or an image as file@address; repeat for each image. | HARDLABS_FIRMWARE |
| --hardlabs-memory | Start the memory chips from what a run saved there (--hardlabs-save-memory; or HARDLABS_MEMORY). | |
| --hardlabs-save-memory | Save what the memory chips hold into this directory when the run ends. | HARDLABS_SAVE_MEMORY |
| --hardlabs-api | API address (default: as hardlabs login saved it). |
Environment variables
| Variable | Description |
|---|---|
| HARDLABS_TOKEN | The API token. Create one on hardlabs.io under Settings → CLI access. Defaults to the token hardlabs login saved. |
| HARDLABS_API_URL | The API's address. Defaults to https://api.hardlabs.io. |
| HARDLABS_SIM | The board pytest tests against, as --hardlabs-sim takes it. |
| HARDLABS_FIRMWARE | The firmware pytest boots, images separated by spaces, as --hardlabs-firmware takes them. |