-
Notifications
You must be signed in to change notification settings - Fork 185
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
feat: Use caplog to test log messages #4315
Conversation
f742a17
to
2df12ba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I just left some nitpicks. Also please squash the commits and rebase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @pkoprda, for a precise review! ❤️ I fixed the issues you spotted and looked through the code for other instances. You spotted them all. Good job!
I was not sure about the squash: I kept the commits separate intentionally. But I have no problems doing so. So squashed and rebased.
Re-requesting a review.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4315 +/- ##
=======================================
Coverage 77.17% 77.17%
=======================================
Files 765 765
Lines 41770 41770
Branches 8821 8821
=======================================
Hits 32238 32238
Misses 8464 8464
Partials 1068 1068
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Thanks, @pkoprda! One more round? |
@Glutexo looks good, just squash the commits and then I will approve it |
Logger asserts are error-prone, because they assert calls, not actual messages. The caplog fixture is Pytest-native way to test logs. This makes integration-level unit tests easier to add. For the caplog fixture to work on Python 2.6 (RHEL 6), pytest_catchlog needs to be installed. On more recent version of python, the fixture is included in Pytest. pytest_catchlog caused pidfile write tests to fail. The fixture itself calls os.getpid, interfering with the patch. Every log message makes a getpid call that is recorded in the patch. assert_not_called patches then stopped working. Fixed by removing the os.getpid patch. The original function is safe to use. test_write_pidfile_not_called verifies several calls among which write_to_disk is the important one, not getpid. Card IDs: * CCT-774 * CCT-963 * CCT-1084 Signed-off-by: Štěpán Tomsa <[email protected]>
Sure thing! Squashed. @pkoprda |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Glutexo, LGTM! The failing test is not related to this change.
@xiangce can we merge this?
EDIT: I opened PR insights-core#4316 to fix that failing test.
@pkoprda You were faster. 😃 I wanted to do that too. |
Logger asserts are error-prone, because they assert calls, not actual messages. The caplog fixture is Pytest-native way to test logs. This makes integration-level unit tests easier to add. For the caplog fixture to work on Python 2.6 (RHEL 6), pytest_catchlog needs to be installed. On more recent version of python, the fixture is included in Pytest. pytest_catchlog caused pidfile write tests to fail. The fixture itself calls os.getpid, interfering with the patch. Every log message makes a getpid call that is recorded in the patch. assert_not_called patches then stopped working. Fixed by removing the os.getpid patch. The original function is safe to use. test_write_pidfile_not_called verifies several calls among which write_to_disk is the important one, not getpid. Card IDs: * CCT-774 * CCT-963 * CCT-1084 Signed-off-by: Štěpán Tomsa <[email protected]> (cherry picked from commit 644d314)
Logger asserts are error-prone, because they assert calls, not actual messages. The caplog fixture is Pytest-native way to test logs. This makes integration-level unit tests easier to add. For the caplog fixture to work on Python 2.6 (RHEL 6), pytest_catchlog needs to be installed. On more recent version of python, the fixture is included in Pytest. pytest_catchlog caused pidfile write tests to fail. The fixture itself calls os.getpid, interfering with the patch. Every log message makes a getpid call that is recorded in the patch. assert_not_called patches then stopped working. Fixed by removing the os.getpid patch. The original function is safe to use. test_write_pidfile_not_called verifies several calls among which write_to_disk is the important one, not getpid. Card IDs: * CCT-774 * CCT-963 * CCT-1084 Signed-off-by: Štěpán Tomsa <[email protected]> (cherry picked from commit 644d314) (cherry picked from commit b22745e)
All Pull Requests:
Check all that apply:
Logger asserts are error-prone, because they assert calls, not actual messages. The
caplog
fixture is Pytest-native way to test logs. This makes integration-level unit tests easier to add.For the
caplog
fixture to work on Python 2.6 (RHEL 6),pytest_catchlog
needs to be installed. On more recent version of Python, the fixture is included in Pytest.pytest_catchlog
caused PID file write tests to fail. The fixture itself callsos.getpid
, interfering with the patch. Every log message makes agetpid
call that is recorded in the patch.assert_not_called
patches then stopped working.Fixed by removing the
os.getpid
patch. The original function is safe to use.test_write_pidfile_not_called
verifies several calls among whichwrite_to_disk
is the important one, notgetpid
.Card IDs: