0

Are there any tools/modules/libraries in python that allow for file comparison? It should allow for regular expressions that can ignore items that shouldn't be compared such as log timestamps, file/line number, etc. but still compare the log level and message part of the log. It will provide for comparing canonical log lines in unit testing.

I have found some related posts such as this but they use unittest framework and also only work on line by line comparisons which doesn't meet my intended use case.

Note: Canonical implies official, so these lines it will be comparing shouldn't change from implementation to implementation. A change in canonical logs indicates a change in behavior. Here is an article on canonical logs.

2
  • If it's solely for unit testing, I would, instead of comparing log files, mock the logger and assert on the calls they receive. – Alejandro Feb 22 at 12:52
  • Thank you for the suggestion but its not only for unit testing. The idea is using canonical statements that apply to live use as well as testing. These statements attempt to capture behavior and are agnostic of the implementation details. – LeanMan Feb 25 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.