Skip to content

fix(infra): correct mock.patch target for build_image_impl in helper_test#15840

Open
Ravi-Dahiya-00 wants to merge 1 commit into
google:masterfrom
Ravi-Dahiya-00:master
Open

fix(infra): correct mock.patch target for build_image_impl in helper_test#15840
Ravi-Dahiya-00 wants to merge 1 commit into
google:masterfrom
Ravi-Dahiya-00:master

Conversation

@Ravi-Dahiya-00

Copy link
Copy Markdown

What changed

In ShellTest.test_base_runner_debug inside infra/helper_test.py, the mock decorator was incorrectly targeting helper.build_image_impl:

# Before (incorrect)
@mock.patch('helper.build_image_impl')

# After (correct)
@mock.patch('common_utils.build_image_impl')

Why it was wrong

build_image_impl is defined in common_utils.py, not in helper.py.

Python's unittest.mock.patch works by replacing the name at the location where it is defined (or where it is imported and used). Since helper.build_image_impl does not exist as a name in the helper module, the patch had no effect — the real build_image_impl function was being called silently during the test, making it neither a true unit test nor reliable in environments without Docker.

Impact

  • The test test_base_runner_debug was not actually isolating the unit under test.
  • Any side effects from the real build_image_impl (e.g., Docker calls) could cause non-deterministic failures in CI.
  • This fix ensures the mock is applied correctly so the test runs fast, isolated, and without external dependencies.

No functional changes

Only the test file is modified. No production code is affected.

@Ravi-Dahiya-00

Copy link
Copy Markdown
Author

@mikeal @alex @bgianfo @haberman hii could you please check it out.

@alex

alex commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Do not ping random users. It's incredible rude. (I'm not a maintainer of this project at all.)

@Ravi-Dahiya-00

Copy link
Copy Markdown
Author

Do not ping random users. It's incredible rude. (I'm not a maintainer of this project at all.)

Sorry, dude. It was just a mistake. I thought you were a maintainer because you have such an awesome profile, man. 😅

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.

2 participants