Skip to content

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

Merged
merged 3 commits into from
Apr 3, 2025

Conversation

WilliamBergamin
Copy link
Contributor

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 entire Request including the WebClient gets copied. It is important that the logger in the WebClient 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

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.signature (Request Signature Verifier)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.models (UI component builders)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.rtm_v2 (RTM client)
  • /docs (Documents)
  • /tutorial (PythOnBoardingBot tutorial)
  • tests/integration_tests (Automated tests for this library)

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

@hello-ashleyintech
Copy link
Contributor

🤔 looks like the test builds are "failing" / not running with the message GitHub Actions has encountered an internal error when running your job. - is this expected @WilliamBergamin?

Copy link
Contributor

@hello-ashleyintech hello-ashleyintech left a 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

Copy link

codecov bot commented Apr 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.33%. Comparing base (8b9c0b9) to head (8faec39).
Report is 1 commits behind head on main.

✅ 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.
📢 Have feedback on the report? Share it here.

Copy link
Member

@zimeg zimeg left a 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")
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🖨️ ✨

@WilliamBergamin WilliamBergamin merged commit 688ea66 into main Apr 3, 2025
12 checks passed
@WilliamBergamin WilliamBergamin deleted the webclient-copyable branch April 3, 2025 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:async tests M-T: Testing work only web-client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants