SDK docs menu

Guides

Console and simulated time

Every wait in the SDK counts simulated time, not real time. A test that waits five seconds waits five seconds of the board's time, so a slow network or a busy server doesn't change the result.

Wait for output

board.wait_for("app ready", within=5)

Board.wait_for returns the first line that contains the text. If none appears in time, it raises ConsoleTimeout, whose message shows what the console printed instead.

A match uses up that line and every line before it. Waiting for the same text again finds the next occurrence:

board.wait_for("sample")    # the first sample
board.wait_for("sample")    # the second, not the first again

Send a command

board.send("status")
board.expect_console("mode: SAFE", "faults: 0")

Board.send types a line and presses Enter. Output printed before the call can't match a later wait, so what you wait for next is the reply. Board.expect_console waits for several lines in order.

Let time pass

board.wait(2.0)              # two seconds of simulated time
print(board.clock())         # simulated seconds since boot

When waits fail

  • ConsoleTimeout: the text didn't appear in time. It is an AssertionError, so pytest reports a failed test rather than an error.
  • SimulationStopped: simulated time stopped advancing, so the wait can't finish. Board.problems usually says why.

One request gives up after 60 real seconds (the timeout argument to Client). To bound a whole test in real time, use pytest-timeout.

Read what was printed

for line in board.lines()[-20:]:
    print(line.n, line.text)

Boards with more than one console take console= on every call. Without it, calls use the board's main console.