In this following code, assert
is used outside of unit test:
import logging
if __name__ == "__main__":
logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO)
logger = logging.getLogger(__name__)
logger.info("info level")
assert 1 == 0
which prints as follows:
2016-02-16 14:56:58,445 - __main__ - INFO - info level
Traceback (most recent call last):
File "logtest.py", line 7, in <module>
assert 1 == 0
AssertionError
What is the "canonical" way to use the timestamped logging format for AssertionError
raised by the assert
(possibly without rewriting each assert
in the code)?
There were a number of similar questions asked, mostly dealing with asserts
in unit testing context ...
Thanks