tbot has its own logging mechanism to provide pretty output during a testcase run and extensive information about it afterwards. The tbot.log module contains the relevant code. Basically, everything centers about EventIO objects, which represent single log-events. These can either be created using one of the many existing log-event function, or manually, if the existing ones are not covering your case.


tbot.log.with_verbosity(verbosity: Verbosity, *, nesting: int | None = None, only_decrease: bool = False) Iterator[None][source]

Temporarily change the verbosity to a different level.


# This command produces a lot of uninteresting output so let's reduce
# verbosity while running it:
with tbot.log.with_verbosity(tbot.log.Verbosity.COMMAND):
    kernel_log = lnx.exec0("dmesg")
  • verbosity – The new verbosity while this context-manager is active.

  • nesting – The (optional) nesting level while this context-manager is active. If not passed, the previous nesting level is retained.

  • only_decrease – Only allow decreasing the verbosity. If a higher verbosity than what is currently active is passed, it will be ignored. only_decrease defaults to False which means any verbosity is accepted.

New in version 0.10.1.

Changed in version 0.10.3: Added the only_decrease parameter.


Boolean that is set if stdout supports unicode.

You should use tbot.log.u() instead of querying this flag.


Boolean that is set if tbot’s output should be colored.

You can use tbot.log.c() as an easy way to colorize your strings.

tbot.log.u(with_unicode: str, without_unicode: str) str[source]

Select a string depending on whether the terminal supports unicode.

  • with_unicode (str) – The string to be used if unicode is available

  • without_unicode (str) – The string to be used if unicode is not available

Return type:



The selected string

class tbot.log.c(s: str) tbot.log.c

Color a string. Reexport from termcolor2


tbot.log.message(tbot.log.c("Message").yellow.bold + ": Hello World!")

s (str) – The string that should be colored

The following ‘attributes’ exist to restyle the text:

Foreground Color

Background Color

Style Attribute





















Log Events

tbot.log.message(msg: str | _C | _C, verbosity: Verbosity = Verbosity.INFO) EventIO[source]

Log a message.

  • msg (str) – The message

  • verbosity (Verbosity) – Message verbosity

tbot.log.warning(msg: str | _C | _C) EventIO[source]

Emit a warning message.


msg (str) – The message

New in version 0.6.3.

tbot.log.skip(what: str | _C | _C) EventIO[source]

Emit a testcase skip message.


what (str) – What test is being skipped

Deprecated since version 0.8: Use tbot.skip() instead.

tbot.log_event.command(mach: str, cmd: str) EventIO[source]

Log a command’s execution.

  • mach (str) – Name of the machine the command is run on

  • cmd (str) – The command itself

Return type:



A stream that the output of the command should be written to.

tbot.log_event.testcase_begin(name: str) None[source]

Log a testcase’s beginning.


name (str) – Name of the testcase

tbot.log_event.testcase_end(name: str, duration: float, success: bool = True, skipped: str | None = None) None[source]

Log a testcase’s end.

  • duration (float) – Time passed while this testcase ran

  • success (bool) – Whether the testcase succeeded

  • skipped (str) – None if the testcase ran normally or a string (the reason) if it was skipped. If a testcase was skipped, success is ignored.


class tbot.log.EventIO(ty: List[str], message: str | _C | _C, *, verbosity: Verbosity = Verbosity.INFO, nest_first: str | None = None, **kwargs: Any)[source]

Bases: StringIO

Stream for a log event.

Create a log event.

A log event is a io.StringIO and everything written to the stream will be added to the log event.


message (str) – First line of the log event (the log message). If the message contains newlines, only the first line will be printed as the message and the rest will be added to the log-event.