Skip to content

Fix test_get_python_sdk_name to use supported Python version#39328

Open
shunping wants to merge 2 commits into
apache:masterfrom
shunping:fix-test-get-python-sdk-name
Open

Fix test_get_python_sdk_name to use supported Python version#39328
shunping wants to merge 2 commits into
apache:masterfrom
shunping:fix-test-get-python-sdk-name

Conversation

@shunping

@shunping shunping commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Update sys.version_info mock from 3.9 to 3.11 in test_get_python_sdk_name and format version check error message using sys.version_info for consistency.

This is needed to fix the failure of UtilTest::test_get_python_sdk_name on a post-release branch, where Beam version has no dev in it.

Failed test run:
https://github.com/apache/beam/actions/runs/29345736526/job/87128821341?pr=39325

Traceback:
(Notice that the error message is misleading though because it does not use the mocked variable. This has also been fixed in this PR)

______________________ UtilTest.test_get_python_sdk_name _______________________
[gw0] linux -- Python 3.10.20 /runner/_work/beam/beam/sdks/python/test-suites/tox/py310/build/srcs/sdks/python/target/.tox-py310-cloud/py310-cloud/bin/python

self = <apache_beam.runners.dataflow.internal.apiclient_test.UtilTest testMethod=test_get_python_sdk_name>

    @mock.patch(
        'apache_beam.runners.dataflow.internal.apiclient.sys.version_info',
        (3, 9))
    def test_get_python_sdk_name(self):
      pipeline_options = PipelineOptions([
          '--project',
          'test_project',
          '--job_name',
          'test_job_name',
          '--temp_location',
          'gs://test-location/temp',
          '--experiments',
          'beam_fn_api',
          '--experiments',
          'use_multiple_sdk_containers'
      ])
>     environment = apiclient.Environment([],
                                          pipeline_options,
                                          '1',
                                          FAKE_PIPELINE_URL)

apache_beam/runners/dataflow/internal/apiclient_test.py:1049: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
target/.tox-py310-cloud/py310-cloud/lib/python3.10/site-packages/apache_beam/runners/dataflow/internal/apiclient.py:139: in __init__
    _verify_interpreter_version_is_supported(options)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

pipeline_options = <apache_beam.options.pipeline_options.PipelineOptions object at 0x7dac1838b160>

    def _verify_interpreter_version_is_supported(pipeline_options):
      if ('%s.%s' % (sys.version_info[0], sys.version_info[1])
          in _PYTHON_VERSIONS_SUPPORTED_BY_DATAFLOW):
        return
    
      if 'dev' in beam_version.__version__:
        return
    
      debug_options = pipeline_options.view_as(DebugOptions)
      if (debug_options.experiments and
          'use_unsupported_python_version' in debug_options.experiments):
        return
    
>     raise Exception(
          'Dataflow runner currently supports Python versions %s, got %s.\n'
          'To ignore this requirement and start a job '
          'using an unsupported version of Python interpreter, pass '
          '--experiment use_unsupported_python_version pipeline option.' %
          (_PYTHON_VERSIONS_SUPPORTED_BY_DATAFLOW, sys.version))
E     Exception: Dataflow runner currently supports Python versions ['3.10', '3.11', '3.12', '3.13', '3.14'], got 3.10.20 (main, Jun 16 2026, 21:01:32) [GCC 13.3.0].
E     To ignore this requirement and start a job using an unsupported version of Python interpreter, pass --experiment use_unsupported_python_version pipeline option.

Update sys.version_info mock from 3.9 to 3.11 in test_get_python_sdk_name
and format version check error message using sys.version_info for consistency.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a test failure in the Dataflow runner's interpreter version verification logic. By updating the mocked Python version in the test suite and refining the error message format, the changes ensure that the verification logic behaves correctly and provides clearer feedback when an unsupported Python version is encountered.

Highlights

  • Test Compatibility: Updated the sys.version_info mock in test_get_python_sdk_name from 3.9 to 3.11 to align with supported Python versions and resolve test failures.
  • Error Reporting: Improved the error message in _verify_interpreter_version_is_supported to use sys.version_info for more accurate and consistent reporting of the detected Python version.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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

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.

Code Review

This pull request updates the unsupported Python version exception message in the Dataflow runner's API client to display only the major and minor version numbers using sys.version_info instead of the full sys.version string. Additionally, it updates a corresponding unit test to mock Python 3.11 instead of Python 3.9. There are no review comments, so no feedback is 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.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @damccorm for label python.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant