-
Notifications
You must be signed in to change notification settings - Fork 846
tests: add tests to ensure web client is copyable #1682
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
Conversation
🤔 looks like the test builds are "failing" / not running with the message |
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.
🙌 test logic LGTM! Thanks for adding this
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## main #1682 +/- ##
==========================================
- Coverage 85.36% 85.33% -0.04%
==========================================
Files 113 113
Lines 12808 12808
==========================================
- Hits 10934 10930 -4
- Misses 1874 1878 +4 ☔ View full report in Codecov by Sentry. |
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.
LGTM! This is a nice case to cover 👾
I'm excited for the added helper functions unlocked in these changes too. This is nice documentation inline 📚
|
||
|
||
class TestWebClientLogger(unittest.TestCase): | ||
test_logger: logging.Logger | ||
|
||
def setUp(self): | ||
self.test_logger = logging.Logger("test-logger") | ||
self.test_logger = logging.getLogger("test-logger") |
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.
WebClient
loggers must be initialized with logging.getLogger since all calls to this function with a given name return the same logger instance.
This is a great TIL!
token="xoxb-api_test", | ||
logger=self.test_logger, | ||
) | ||
client_copy = create_copy(client) |
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.
🖨️ ✨
Summary
Following slackapi/bolt-python#1284 it was found that passing specific instances of Loggers into the
WebClient
may make it not copyable. When using Bolt for python in a lazy listener configuration the entireRequest
including theWebClient
gets copied. It is important that thelogger
in theWebClient
is copiable in order to maintain this behavior.WebClient
loggers must be initialized with logging.getLogger since all calls to this function with a given name return the same logger instance. This means that logger instances never need to be passed between different parts of an application, and make them copiable.This PR introduces a unit test that ensure the
WebClient
with a custom logger remains copyable.Testing
Run the unit tests
Category
/docs
(Documents)/tutorial
(PythOnBoardingBot tutorial)tests
/integration_tests
(Automated tests for this library)Requirements
python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh
after making the changes.