Skip to content

tests: add tests to ensure web client is copyable - #1682

Merged
WilliamBergamin merged 3 commits into
mainfrom
webclient-copyable
Apr 3, 2025
Merged

tests: add tests to ensure web client is copyable#1682
WilliamBergamin merged 3 commits into
mainfrom
webclient-copyable

Conversation

@WilliamBergamin

Copy link
Copy Markdown
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
Copy Markdown
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?

@hello-ashleyintechhello-ashleyintech left a comment

Copy link
Copy Markdown
Contributor

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

codecovBot commented Apr 2, 2025

Copy link
Copy Markdown

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.

@zimegzimeg left a comment

Copy link
Copy Markdown
Member

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 📚


def setUp(self):
self.test_logger = logging.Logger("test-logger")
self.test_logger = logging.getLogger("test-logger")

Copy link
Copy Markdown
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
Copy Markdown
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 mainApr 3, 2025
@WilliamBergamin
WilliamBergamin deleted the webclient-copyable branch April 3, 2025 14:36
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:asynctestsM-T: Testing work onlyweb-client

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@WilliamBergamin@hello-ashleyintech@zimeg