Skip to content

PYTHON-5920 - Use mock instead of patching for test_network_layer.py - #2920

Merged
NoahStapp merged 1 commit into
mongodb:masterfrom
NoahStapp:PYTHON-5920
Jul 7, 2026
Merged

NoahStapp merged 1 commit into
mongodb:masterfrom
NoahStapp:PYTHON-5920

Conversation

@NoahStapp

Copy link
Copy Markdown
Contributor

PYTHON-5920

Changes in this PR

Replace the patching in test_network_layer.py with a scoped mock to avoid race conditions.

Test Plan

Test changes.

Checklist

Checklist for Author

  • [ ] Did you update the changelog (if necessary)?
  • Is there test coverage?
  • [ ] Is any followup work tracked in a JIRA ticket? If so, add link(s).

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

Copilot AI review requested due to automatic review settings July 7, 2026 19:45
@NoahStapp
NoahStapp requested a review from a team as a code owner July 7, 2026 19:45
@NoahStapp
NoahStapp requested a review from blink1073 July 7, 2026 19:45

Copilot AI 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.

Pull request overview

This PR updates the synchronous unit tests for pymongo.network_layer to avoid patching module-level functions (receive_data) and instead mock socket reads on a per-connection basis, reducing the chance of cross-test/thread interference.

Changes:

  • Removed patch-based mocking of network_layer.receive_data in TestReceiveMessage.
  • Added _mock_recv_into helper to scope mocked reads to a specific connection’s recv_into.
  • Updated affected receive_message tests to use _mock_recv_into with deterministic byte chunks.

Comment thread test/test_network_layer.py Resolved
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@blink1073 blink1073 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

@NoahStapp
NoahStapp merged commit c9b2331 into mongodb:master Jul 7, 2026
88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants