Sometimes code can be hard to test because it doesn't return anything. If you can run the code, adding logging is a relatively safe thing to do. Then if you can capture those logs in your tests, you can start to safely refactor and even modify existing behavior with confidence.
There are 2 apis for testing logs, although they both work in the same manner.
This easiest way to test with simple logger is to use the with verify_simple_logger:
which will
capture everything logged in the follow context and verify it.
Example:
def test_variable():
with verify_simple_logger():
SimpleLogger.variable("dalmatians", 101, show_types=True)
SimpleLogger.variable("dalmatians", 101, show_types=False)
which produces:
variable: dalmatians = 101 <int>
variable: dalmatians = 101
Alternatively, you can achive the same result by logging to a string and then verifing the result
Example:
def test_variable_explict():
output = SimpleLogger.log_to_string()
SimpleLogger.variable("dalmatians", 101, show_types=True)
SimpleLogger.variable("dalmatians", 101, show_types=False)
verify(output)