test: fix vacuous registry-cleanup assertion in test_mode_registry#1921
Closed
arham766 wants to merge 1 commit into
Closed
test: fix vacuous registry-cleanup assertion in test_mode_registry#1921arham766 wants to merge 1 commit into
arham766 wants to merge 1 commit into
Conversation
The final assertion compared the string 'test_registry' against registry OBJECTS in _ModeRegistryCls._all_registries, so it passed vacuously regardless of behavior. It also masked two real warts, now documented in the test: __del__ is unreachable because _all_registries holds a strong reference (del never drops the refcount to zero), and if the registry is removed from the list first, a later GC-triggered __del__ raises ValueError from its unconditional list.remove. The test now asserts the removed mode no longer resolves via any registry, removes the registry from _all_registries explicitly (neutralizing __del__ for the deterministic destruction), and checks residue by name - verified non-vacuous by mutation (skipping the removal makes it fail). Part of the findings in NVIDIA#1902 (wave 2). Signed-off-by: arham766 <arhamislam766@yahoo.com>
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughA test file for mode registry functionality was updated to import mock and pytest, add assertions verifying that a removed mode is no longer resolvable and raises KeyError, and rework test cleanup to explicitly remove registry instances and patch ChangesTest enhancement for mode registry
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Contributor
Author
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.
What does this PR do?
Type of change: Bug fix
Test-only fix (found writing #1915): test_mode_registry.py's final assertion compared the STRING 'test_registry' against registry OBJECTS in _all_registries — vacuously true regardless of behavior. It masked two real warts, now documented in-test: _ModeRegistryCls.del is unreachable (the class-level list holds a strong reference), and if a registry is removed from the list first, a later GC-triggered del raises ValueError from its unconditional list.remove (surfaced as PytestUnraisableExceptionWarning). The test now asserts the removed mode no longer resolves, cleans the registry from _all_registries explicitly, and checks residue by name — mutation-verified non-vacuous. The del warts may deserve a small source fix; happy to follow up.
Usage
N/A
Testing
Regression tests included, each verified to FAIL with the fix reverted. Combined battery with all sibling wave fixes: 381 passed across tests/unit/torch/opt, tests/unit/torch/utils, tests/unit/recipe, and quantization test_mode. Note: the unmerged suite PRs #1913-#1916 contain behavior-documenting NOTE tests pinning the OLD behavior fixed here — whichever lands second gets the NOTE tests flipped (happy to rebase either way).
Before your PR is "Ready for review"
Additional Information
Issue: #1902 (wave-2 findings)
Summary by CodeRabbit