def METHOD_NAME(connect_mode, expected_state, resume):
    print("Connecting with connect_mode=%s" % connect_mode)
    live_session = ConnectHelper.session_with_chosen_probe(
                    unique_id=board_id,
                    init_board=False,
                    connect_mode=connect_mode,
                    resume_on_disconnect=resume,
                    **get_session_options())
    live_session.open()
    live_board = live_session.board
    print("Verifying target is", STATE_NAMES.get(expected_state, "unknown"))
    actualState = live_board.target.get_state()
    # Accept sleeping for running, as a hack to work around nRF52840-DK test binary.
    # TODO remove sleeping hack.
    if (actualState == expected_state) \
            or (expected_state == RUNNING and actualState == Target.State.SLEEPING):
        passed = 1
        print("TEST PASSED")
    else:
        passed = 0
        print("TEST FAILED (state={}, expected={})".format(
            STATE_NAMES.get(actualState, "unknown"),
            STATE_NAMES.get(expected_state, "unknown")))
    print("Disconnecting with resume=%s" % resume)
    live_session.close()
    live_session = None
    return passed