PYTHON-5874 Fix test_fork.py failures on Python 3.15 due to fork() DeprecationWarning - #3040
Merged
blink1073 merged 2 commits intoSep 4, 2026
Merged
Conversation
…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.
Contributor
There was a problem hiding this comment.
🟢 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-threadDeprecationWarninginside the sharedIntegrationTest.forkhelper (scoped to justproc.start()). - Remove the Python 3.15+
skipIfstopgap fromtest/test_fork.pyso 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.
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.
|
Assigned |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PYTHON-5874
Python 3.12+ emits a
DeprecationWarningwhenos.fork()is called in a multi-threaded process, which the test suite'sfilterwarnings = ["error"]turns into a failure for thetest_fork.pytests. These tests intentionally fork a running client whoseregister_at_forkhandlers reset its locks in the child, so the warning is benign; suppress it in theself.forkhelper and remove the 3.15skipIfstopgap.Changes in this PR
os.fork()DeprecationWarninginside theself.forktest helper, scoped to that specific warning.skipIfthat skippedtest_fork.pyon Python 3.15+ (stopgap from PYTHON-5837) so the tests run on 3.15+.Test Plan
test/test_fork.pyon Python 3.15.0rc1: 3/3 pass (previously 2 failed with theDeprecationWarning).test/test_fork.pyon Python 3.13: 3/3 pass (no regression).Checklist
Checklist for Author
Checklist for Reviewer