Skip to content

refactor: use python_ext mock helpers in python_tests.bzl#3813

Open
rickeylev wants to merge 1 commit into
bazel-contrib:mainfrom
rickeylev:refactor-python-tests-mocks
Open

refactor: use python_ext mock helpers in python_tests.bzl#3813
rickeylev wants to merge 1 commit into
bazel-contrib:mainfrom
rickeylev:refactor-python-tests-mocks

Conversation

@rickeylev
Copy link
Copy Markdown
Collaborator

Refactored tests/python/python_tests.bzl to use the shared python_ext mock helpers instead of standalone mock helpers.

@rickeylev rickeylev requested a review from aignas as a code owner June 7, 2026 08:42
@rickeylev rickeylev enabled auto-merge June 7, 2026 08:43
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the python tests by extracting local mock helper functions into a centralized mock helper library, python_ext.bzl, and updating the tests to use it. Feedback on the new helper library points out that the _override and _defaults mock helpers are missing several default attributes (auth_patterns, netrc, and python_version_file), which could cause errors in tests if accessed when not explicitly provided.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +26 to +39
def _override(**kwargs):
"""Creates a mock python.override tag with default values."""
attrs = {
"add_runtime_manifest_urls": [],
"add_target_settings": [],
"available_python_versions": [],
"base_url": "https://github.com/astral-sh/python-build-standalone/releases/download",
"ignore_root_user_error": True,
"minor_mapping": {},
"register_all_versions": False,
"runtime_manifest_sha": "",
}
attrs.update(kwargs)
return mocks.tag(**attrs)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The mock _override helper is missing the auth_patterns and netrc attributes in its default attrs dictionary. If these attributes are accessed on the returned mock tag in tests or implementation code when they are not explicitly passed, it will result in a struct has no field error. Adding them with default values ensures the mock tag is robust and matches the real tag's schema.

Suggested change
def _override(**kwargs):
"""Creates a mock python.override tag with default values."""
attrs = {
"add_runtime_manifest_urls": [],
"add_target_settings": [],
"available_python_versions": [],
"base_url": "https://github.com/astral-sh/python-build-standalone/releases/download",
"ignore_root_user_error": True,
"minor_mapping": {},
"register_all_versions": False,
"runtime_manifest_sha": "",
}
attrs.update(kwargs)
return mocks.tag(**attrs)
def _override(**kwargs):
"""Creates a mock python.override tag with default values."""
attrs = {
"add_runtime_manifest_urls": [],
"add_target_settings": [],
"auth_patterns": {},
"available_python_versions": [],
"base_url": "https://github.com/astral-sh/python-build-standalone/releases/download",
"ignore_root_user_error": True,
"minor_mapping": {},
"netrc": "",
"register_all_versions": False,
"runtime_manifest_sha": "",
}
attrs.update(kwargs)
return mocks.tag(**attrs)

Comment on lines +41 to +48
def _defaults(**kwargs):
"""Creates a mock python.defaults tag with default values."""
attrs = {
"python_version": "",
"python_version_env": "",
}
attrs.update(kwargs)
return mocks.tag(**attrs)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The mock _defaults helper is missing the python_version_file attribute in its default attrs dictionary. If this attribute is accessed on the returned mock tag when it is not explicitly passed, it will result in a struct has no field error. Adding it with a default empty string ensures the mock tag matches the real tag's schema.

Suggested change
def _defaults(**kwargs):
"""Creates a mock python.defaults tag with default values."""
attrs = {
"python_version": "",
"python_version_env": "",
}
attrs.update(kwargs)
return mocks.tag(**attrs)
def _defaults(**kwargs):
"""Creates a mock python.defaults tag with default values."""
attrs = {
"python_version": "",
"python_version_env": "",
"python_version_file": "",
}
attrs.update(kwargs)
return mocks.tag(**attrs)

Refactored tests/python/python_tests.bzl to use the shared python_ext mock
helpers instead of standalone mock helpers.
@rickeylev rickeylev force-pushed the refactor-python-tests-mocks branch from 395bcd5 to 80cd02b Compare June 7, 2026 08:44
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