Skip to content

fix(tests): test_doctor.py MagicMock auto-vivifies args.check, breaks 11 tests - #232

Merged
Wolfvin merged 1 commit into
mainfrom
fix/test-doctor-magicmock-check-attribute
Jul 12, 2026
Merged

fix(tests): test_doctor.py MagicMock auto-vivifies args.check, breaks 11 tests#232
Wolfvin merged 1 commit into
mainfrom
fix/test-doctor-magicmock-check-attribute

Conversation

@Wolfvin

@Wolfvin Wolfvin commented Jul 12, 2026

Copy link
Copy Markdown
Owner

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 --check dispatch to doctor.execute() — when getattr(args, "check", None) is truthy, it goes through _dispatch_subcommands() instead of the normal full-checks path. mock.MagicMock() auto-vivifies any attribute access, so args.check silently returns a fresh MagicMock (truthy), never None — every test using the shared _run_doctor() helper (or constructing args inline) unknowingly exercised the wrong code path.

Fix: explicitly set args.check = None in _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.

@Wolfvin
Wolfvin merged commit 9655a09 into main Jul 12, 2026
@Wolfvin
Wolfvin deleted the fix/test-doctor-magicmock-check-attribute branch July 12, 2026 05:34
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

1 participant