PYTHON-5428 - @flaky calls cleanup between attempts - #3006
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the internal @flaky test decorator used across the PyMongo test suite to reduce cross-attempt interference by running test cleanups between retry attempts (aimed at preventing leaked clients/listeners from impacting subsequent retries). It also updates the stated reason for one flaky SDAM test in both sync and async variants.
Changes:
- Add a cleanup step to
@flakyto run registeredunittest.TestCasecleanups between retry attempts. - Extend
@flakywrapper logic to locate the activeunittest.TestCaseinstance (unbound “prose” vs bound “unified” execution paths). - Update the flaky annotation reason for
test_connection_close_does_not_block_other_operations(sync + async).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
test/utils.py |
Adds between-attempt cleanup execution to the sync @flaky decorator. |
test/asynchronous/utils.py |
Adds between-attempt cleanup execution to the async @flaky decorator (awaiting async cleanups). |
test/test_discovery_and_monitoring.py |
Updates the flaky reason string for a slow test. |
test/asynchronous/test_discovery_and_monitoring.py |
Updates the flaky reason string for the async variant of the same test. |
Suppressed comments (2)
test/utils.py:212
- depth is recomputed at the start of every retry attempt. This prevents cleanups added by reset_func (e.g., setUp) from being considered part of the next attempt, so they won't be run on subsequent failures and can accumulate across retries.
passes = 0
for i in range(max_runs):
depth = len(method._cleanups) if method is not None else 0
try:
test/asynchronous/utils.py:212
- depth is recomputed at the start of every retry attempt. This prevents cleanups added by reset_func (e.g., asyncSetUp) from being considered part of the next attempt, so they won't be run on subsequent failures and can accumulate across retries.
passes = 0
for i in range(max_runs):
depth = len(method._cleanups) if method is not None else 0
try:
💡 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! |
|
4.2 failures are expected until #2892 is merged. |
PYTHON-5428
Changes in this PR
Our
@flakydecorator did not call test cleanups between attempts. This resulted in resources such as clients remaining open and interfering with event listening on later retry attempts. This PR adds a cleanup step to@flakythat ensures all registered cleanups are called between attempts.Test Plan
N/A
Checklist
Checklist for Author
[ ] Did you update the changelog (if necessary)?[ ] Is any followup work tracked in a JIRA ticket? If so, add link(s).Checklist for Reviewer