unit testing – What is verbosity level exactly in python?(difference between each level)

unit testing – What is verbosity level exactly in python?(difference between each level)

Verbosity level is related just to logging. In unit tests you find it for the logging of the information.

Note: It is more pythonic to use levels as constant names(logging.INFO, logging.DEBUG rather than numbers.

These levels decide the amount of information you will get. For example setting the level to ERROR for running unit tests will display only the cases for which the unit tests failed. Setting it to DEBUG will give you more (the most in fact) info such as what were the values of the variables (in assert statements etc).

It is more useful in cases where your program has different levels of logging and you want your users to see different levels of info. For eg. usually you dont want the users to see details of internals, apart from fatal errors. So users will be running the program in FATAL or CRITICAL mode. But when some error occurs you will need such details. In this case you will run the program in debug mode. You can issue custom messages with these levels too. For eg, if you are providing back compatibility with older versions of your program, you can WARN them with logging.warn(), which will be issued only when the logging level is warning or less.


DOCS:

Level related stuff

Default levels and level names, these can be replaced with any positive set
of values having corresponding names. There is a pseudo-level, NOTSET, which
is only really there as a lower limit for user-defined levels. Handlers and
loggers are initialized with NOTSET so that they will log all messages, even
at user-defined levels.

CRITICAL = 50 
FATAL = CRITICAL
ERROR = 40 
WARNING = 30 
WARN = WARNING
INFO = 20 
DEBUG = 10 
NOTSET = 0

unit testing – What is verbosity level exactly in python?(difference between each level)

Leave a Reply

Your email address will not be published. Required fields are marked *