Debugging through logging
Debugging is, after all, detecting what's going on inside our program and finding out what unexpected or incorrect effects may be happening. A simple, yet very effective, approach is to output variables and other information at strategic parts of your code to allow the programmer to follow the flow of the program.
The simplest form of this approach is called print debugging. This technique consists of inserting print statements at certain points to print the value of variables or points while debugging.
But taking this technique a little further and combining it with the logging techniques presented in Chapter 2, Automating Tasks Made Easy, allows us to create a trace of the execution of the program. This tracing information can be really useful when detecting issues in a running program. Logs are also typically displayed when running tests using a test framework.
pytest
, introduced in Chapter 12, Automatic Testing Routines, automatically...