SDK docs menu

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 -> Board

It 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) -> SerialBridge

Calling 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_fresh

Command-line options

OptionDescriptionEnvironment variable
--hardlabs-simThe simulation to test against: owner/project[@version].HARDLABS_SIM
--hardlabs-firmwareFirmware to boot: an ELF, or an image as file@address; repeat for each image.HARDLABS_FIRMWARE
--hardlabs-memoryStart the memory chips from what a run saved there (--hardlabs-save-memory; or HARDLABS_MEMORY).
--hardlabs-save-memorySave what the memory chips hold into this directory when the run ends.HARDLABS_SAVE_MEMORY
--hardlabs-apiAPI address (default: as hardlabs login saved it).

Environment variables

VariableDescription
HARDLABS_TOKENThe API token. Create one on hardlabs.io under Settings → CLI access. Defaults to the token hardlabs login saved.
HARDLABS_API_URLThe API's address. Defaults to https://api.hardlabs.io.
HARDLABS_SIMThe board pytest tests against, as --hardlabs-sim takes it.
HARDLABS_FIRMWAREThe firmware pytest boots, images separated by spaces, as --hardlabs-firmware takes them.