-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default behavior for unit tests: Fail if Errors are being logged and not Asserted. #138
Comments
Can you give some examples of what tests using this facility would look like? |
One way I can think of that would not be far from the current implementation would look like:
would fail with and Assertion error like "Unasserted Error message Logged...." and the developer would need to "fix" the code \ with a check confirming that it is OK for that context to log an error:
what do you think? |
Which of the following would you expect to cause a test failure:
|
I would expect to see failure for: 1 if enforce_checking=True ; 4; 5; 6; 7. Now, with 6 and 7 the implementation can be tricky, and we could decide the a call to actual() "checks all entries" and However I think we can do more:
On a second thought I think the LogCapture class should implement the Sequence interface and one could directly do: assert ('root', 'ERROR', 'message 2') in l and we can use the same logic I proposed above and consider a contains return true as a valid "check" ... let me know what you think cheers. |
I'd be interested to see a PR with the cases above as tests, showing their output when they fail, but I suspect this may be more work that you expect. |
Will give it a try. |
@cjw296 what are the python version compatibility requirements? |
Hi, here is an attempt: #140 |
#138 Add default log check(assert) requirements for LogCapture
This is similar in ideology with failing a unit test that throws an unexpected exception. (Not asserted)
I have implemented this in Java (and more), see detail at: http://www.spf4j.org/spf4j-slf4j-test/index.html
textfixtures has nice log assertion utilities, and together with a "throwAssertionExceptionOnErrorLog()" that will throw an assertion error if a unit test logs an error and it does not assert it(expect it) would be so awesome!
I have been using this behavior in the Java world for a few years and it highlighted and stopped lots of issues from being shipped to production. A side effect I have seen is that developer logging will be more correct.
I really miss this in the python world..
The text was updated successfully, but these errors were encountered: