tbot.log

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.

Helpers

tbot.log.IS_UNICODE

Boolean that is set if stdout supports unicode.

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

tbot.log.IS_COLOR

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.

Parameters
  • 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

str

Returns

The selected string

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

Color a string. Reexport from termcolor2

Example:

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

s (str) – The string that should be colored

The following ‘attributes’ exist to restyle the text:

Foreground Color

Background Color

Style Attribute

.red

.on_red

.bold

.green

.on_green

.dark

.yellow

.on_yellow

.underline

.blue

.on_blue

.blink

.magenta

.on_magenta

.reverse

.cyan

.on_cyan

.concealed

.white

.on_white

Log Events

tbot.log.message(msg: Union[str, termcolor2._C], verbosity: tbot.log.Verbosity = <Verbosity.INFO: 1>)tbot.log.EventIO[source]

Log a message.

Parameters
  • msg (str) – The message

  • verbosity (Verbosity) – Message verbosity

tbot.log.warning(msg: Union[str, termcolor2._C])tbot.log.EventIO[source]

Emit a warning message.

Parameters

msg (str) – The message

New in version 0.6.3.

tbot.log.skip(what: Union[str, termcolor2._C])tbot.log.EventIO[source]

Emit a testcase skip message.

Parameters

what (str) – What test is being skipped

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

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

Log a command’s execution.

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

  • cmd (str) – The command itself

Return type

EventIO

Returns

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.

Parameters

name (str) – Name of the testcase

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

Log a testcase’s end.

Parameters
  • 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.

EventIO

class tbot.log.EventIO(ty: List[str], message: Union[str, termcolor2._C], *, verbosity: tbot.log.Verbosity = <Verbosity.INFO: 1>, nest_first: Optional[str] = None, **kwargs: Any)[source]

Bases: _io.StringIO

Stream for a log event.

Create a log event.

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

Parameters

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.