Skip to content

PYTHON-5874 Fix test_fork.py failures on Python 3.15 due to fork() DeprecationWarning - #3040

Merged
blink1073 merged 2 commits into
mongodb:mainfrom
blink1073:PYTHON-5874-fix-fork-tests-py315
Sep 4, 2026
Merged

PYTHON-5874 Fix test_fork.py failures on Python 3.15 due to fork() DeprecationWarning#3040
blink1073 merged 2 commits into
mongodb:mainfrom
blink1073:PYTHON-5874-fix-fork-tests-py315

Conversation

@blink1073

Copy link
Copy Markdown
Member

PYTHON-5874

Python 3.12+ emits a DeprecationWarning when os.fork() is called in a multi-threaded process, which the test suite's filterwarnings = ["error"] turns into a failure for the test_fork.py tests. These tests intentionally fork a running client whose register_at_fork handlers reset its locks in the child, so the warning is benign; suppress it in the self.fork helper and remove the 3.15 skipIf stopgap.

Changes in this PR

  • Suppress the Python 3.12+ os.fork() DeprecationWarning inside the self.fork test helper, scoped to that specific warning.
  • Removed the skipIf that skipped test_fork.py on Python 3.15+ (stopgap from PYTHON-5837) so the tests run on 3.15+.

Test Plan

  • test/test_fork.py on Python 3.15.0rc1: 3/3 pass (previously 2 failed with the DeprecationWarning).
  • test/test_fork.py on Python 3.13: 3/3 pass (no regression).
  • ruff, ruff-format, and mypy clean on the changed files.

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)? — not necessary; test-only change with no driver behavior change.
  • Is there test coverage? — the fix is to existing tests; no new coverage needed.
  • Is any followup work tracked in a JIRA ticket? If so, add link(s). — documentation note tracked on PYTHON-5874 (Documentation Changes = Needed); docs live externally on mongodb.com.

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?

…precationWarning

Python 3.12 emits a DeprecationWarning when os.fork() runs in a multi-threaded process. The fork tests intentionally fork with the client's background threads running, so the warning is expected; suppress it at the fork site so the error-level warning filter does not fail the tests. Removes the 3.15 skipIf stopgap added in PYTHON-5837.

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.

🟢 Approval recommended

The warning suppression is narrowly scoped to the intentional fork helper and the removed 3.15+ skip is justified by that targeted mitigation.

Pull request overview

This PR updates the PyMongo test harness to keep test_fork.py running on Python 3.12+ (including 3.15) by suppressing the new os.fork() multi-threaded DeprecationWarning only at the point where the test suite intentionally forks, rather than skipping the tests.

Changes:

  • Suppress Python 3.12+ os.fork() multi-thread DeprecationWarning inside the shared IntegrationTest.fork helper (scoped to just proc.start()).
  • Remove the Python 3.15+ skipIf stopgap from test/test_fork.py so the fork tests execute on 3.15+.
  • Add/adjust comments explaining why the warning is benign in this test scenario (PYTHON-5874).
File summaries
File Description
test/test_fork.py Removes the 3.15+ skip and documents that the fork helper suppresses the warning for intentional forks.
test/asynchronous/init.py Adds a localized warnings filter around proc.start() in the fork helper to ignore the fork DeprecationWarning.
test/init.py Mirrors the same localized warnings suppression in the synchronous test helper.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread test/__init__.py Outdated
Comment thread test/asynchronous/__init__.py Outdated
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Clarify that pymongo's locks are reset via register_at_fork in the child.
@blink1073
blink1073 marked this pull request as ready for review September 4, 2026 00:00
@blink1073
blink1073 requested a review from a team as a code owner September 4, 2026 00:00
@blink1073
blink1073 requested a review from NoahStapp September 4, 2026 00:00
@codeowners-service-app

Copy link
Copy Markdown

Assigned aclark4life for team dbx-python because NoahStapp is out of office.

@aclark4life aclark4life 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.

LGTM

@blink1073
blink1073 merged commit 2a4a004 into mongodb:main Sep 4, 2026
90 checks passed
@blink1073
blink1073 deleted the PYTHON-5874-fix-fork-tests-py315 branch September 4, 2026 18:21
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.

3 participants