Adding logs while developing
Any test runner will capture logs and display it as part of the trace while running tests.
pytest
, which we introduced in Chapter 10, Testing and TDD, will display logs as part of the result of a failing test.
This is a good opportunity to check that the expected logs are being generated while the feature is still in development phase, especially if it's done in a TDD process where the failing tests and errors are produced routinely as part of the process, as we saw in Chapter 10, Testing and TDD. Any test that checks an error should also add a corresponding log and, while developing the feature, check that they are being produced.
You can explicitly add to the test a check to validate that the log is being generated by using a tool like pytest-catchlog
(https://pypi.org/project/pytest-catchlog/).
Typically, though, we just take a bit of care and incorporate the practice of checking while using TDD practices as...