refactor: use python_ext mock helpers in python_tests.bzl#3813
refactor: use python_ext mock helpers in python_tests.bzl#3813rickeylev wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
| 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) |
| 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) |
There was a problem hiding this comment.
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.
| 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.
395bcd5 to
80cd02b
Compare
Refactored tests/python/python_tests.bzl to use the shared python_ext mock helpers instead of standalone mock helpers.