How to Capture and Log Tracebacks (Stack trace) in Python

Once you’ve caught an exception, you can capture and log a message with the exception info (including full stack traceback), using logging.exception() or logging.error(). With logging.exception(): With logging.error() we must set the exc_info keyword argument to True (default is False): In both cases, the Error occurred message is logged with level ERROR on the root […]

Pytest Print or Dump Variables to Console for Debugging

Trying to print(var) in your pytest tests and wondering why you cannot see the output in your terminal’s standard output? This is because by default pytest captures all output sent to stdout and stderr, i.e., it intercepts the data going into the low-level file descriptors 1 and 2. This is a good idea because pytest […]