fix(tests): test_doctor.py MagicMock auto-vivifies args.check, breaks 11 tests - #232
Merged
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
… 11 tests Issue #195's --check dispatch (doctor.execute() -> _dispatch_subcommands() when getattr(args, 'check', None) is truthy) introduced an implicit requirement: callers must explicitly set args.check = None to exercise the normal full-checks path. mock.MagicMock() auto-vivifies any attribute access — args.check silently returns a fresh MagicMock object (truthy), not None, so getattr's default never kicks in. Every test using _run_doctor() (or constructing its own MagicMock args inline) unknowingly went through _dispatch_subcommands() instead, getting the umbrella {s, st, r} shape instead of doctor's own {status, exit_code, checks, fixes, summary, platform, workspace} shape -- hence 'assert status in result' / 'KeyError: fixes' failures. Found via baseline comparison: these 11 test_doctor.py failures did NOT exist before today's session (commit c722f4a) -- they were introduced as an unintended side effect of issue #195's consolidation work, not caught at the time because doctor.py's own test suite wasn't run against the new dispatch path with an explicit check=None default. Fix: set args.check = None in _run_doctor() and the 2 inline MagicMock constructions in TestFixMode. Before: 12 failed. After: 1 failed (os.geteuid() -- pre-existing, Windows doesn't have geteuid, confirmed present in baseline too), 37 passed.
|
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.



Found via baseline test-suite comparison — comparing full pytest run at commit c722f4a (before this session's work) vs current main showed 11 NEW test_doctor.py failures that didn't exist in baseline.
Root cause: issue #195 added a
--checkdispatch todoctor.execute()— whengetattr(args, "check", None)is truthy, it goes through_dispatch_subcommands()instead of the normal full-checks path.mock.MagicMock()auto-vivifies any attribute access, soargs.checksilently returns a fresh MagicMock (truthy), neverNone— every test using the shared_run_doctor()helper (or constructing args inline) unknowingly exercised the wrong code path.Fix: explicitly set
args.check = Nonein_run_doctor()and 2 inline MagicMock constructions.Before: 12 failed. After: 1 failed (
os.geteuid()— Windows doesn't have it, confirmed present in baseline too, unrelated pre-existing issue), 37 passed.