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.with_verbosity(verbosity: Verbosity, *, nesting: int | None = None, only_decrease: bool = False) Iterator[None] [source]¶
Temporarily change the verbosity to a different level.
Example:
# 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")
- Parameters:
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 toFalse
which means any verbosity is accepted.
New in version 0.10.1.
Changed in version 0.10.3: Added the
only_decrease
parameter.
- 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.
- 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: str | _C | _C, verbosity: Verbosity = Verbosity.INFO) EventIO [source]¶
Log a message.
- Parameters:
msg (str) – The message
verbosity (Verbosity) – Message verbosity
- tbot.log.warning(msg: str | _C | _C) EventIO [source]¶
Emit a warning message.
- Parameters:
msg (str) – The message
New in version 0.6.3.
- tbot.log.skip(what: str | _C | _C) 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.testcase_begin(name: str) None [source]¶
Log a testcase’s beginning.
- Parameters:
name (str) – Name of the testcase
EventIO
¶
- 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.- 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.