Skip to content

Disable local Google Cloud credentials in cirq-google tests#8083

Merged
pavoljuhas merged 3 commits into
quantumlib:mainfrom
pavoljuhas:block-gcloud-credentials-in-cirq_google-tests
May 21, 2026
Merged

Disable local Google Cloud credentials in cirq-google tests#8083
pavoljuhas merged 3 commits into
quantumlib:mainfrom
pavoljuhas:block-gcloud-credentials-in-cirq_google-tests

Conversation

@pavoljuhas
Copy link
Copy Markdown
Collaborator

@pavoljuhas pavoljuhas commented May 19, 2026

Prevent cirq_google.engine tests from connecting to the actual
services with local user credentials. Tell gcloud to use empty
configuration directory instead of user configuration and also
unset GOOGLE_APPLICATION_CREDENTIALS from the environment.

Ref: https://google-auth.readthedocs.io/en/latest/reference/google.auth.html

May resolve b/511678310

Prevent `cirq_google.engine` tests from connecting to the actual
services with local user credentials.  Tell gcloud to use empty
configuration directory instead of user configuration.
@pavoljuhas pavoljuhas requested review from a team, hoisinberg, verult and wcourtney as code owners May 19, 2026 18:12
@github-actions github-actions Bot added the size: S 10< lines changed <50 label May 19, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.63%. Comparing base (3bc60a8) to head (9fc8268).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8083      +/-   ##
==========================================
- Coverage   99.63%   99.63%   -0.01%     
==========================================
  Files        1110     1110              
  Lines      100242   100438     +196     
==========================================
+ Hits        99879   100072     +193     
- Misses        363      366       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pavoljuhas pavoljuhas added the ci/no-release Use this label for pull request that should not have Cirq pre-release on PyPI. label May 19, 2026
@pavoljuhas pavoljuhas requested a review from mhucka May 20, 2026 00:21
Copy link
Copy Markdown
Collaborator

@dstrain115 dstrain115 left a comment

Choose a reason for hiding this comment

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

Sweet. I hate when I run tests and it complains about cloud credentials.

Comment thread cirq-google/cirq_google/conftest.py Outdated

@pytest.fixture(scope="session", autouse=True)
def disable_local_gcloud_credentials(tmp_path_factory):
# Ensure tests cannot authenticate to production servers with user credentials
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Might be worth changing this to a triple quote docstring.

Also, I would appreciate a comment as to how this prevents cloud authentication to production. It's not totally obvious why this directory and environment variable fixes it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in df1b7ef.

Comment thread cirq-google/cirq_google/conftest.py Outdated
def disable_local_gcloud_credentials(tmp_path_factory):
# Ensure tests cannot authenticate to production servers with user credentials
empty_dir = tmp_path_factory.mktemp("empty_gcloud_config-cirq_google", numbered=False)
with mock.patch.dict(os.environ, {"CLOUDSDK_CONFIG": str(empty_dir)}):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this break any other tests that would happen to use os.environ for other variables? (not sure if we use os environment anywhere else, but I could see us using it for a flag at some point).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Nope, patch.dict by default updates the dictionary with its second argument, i.e., everything except CLOUDSDK_CONFIG is left in os.environ as is.

That said, I changed this in df1b7ef to completely replace os.environ with its sanitized content.

Also scrub the `GOOGLE_APPLICATION_CREDENTIALS` environment variable.

Ref: https://google-auth.readthedocs.io/en/latest/reference/google.auth.html
@pavoljuhas pavoljuhas requested a review from dstrain115 May 20, 2026 23:08
@pavoljuhas pavoljuhas added this pull request to the merge queue May 21, 2026
Merged via the queue into quantumlib:main with commit d1cab35 May 21, 2026
44 checks passed
@pavoljuhas pavoljuhas deleted the block-gcloud-credentials-in-cirq_google-tests branch May 21, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/no-release Use this label for pull request that should not have Cirq pre-release on PyPI. size: S 10< lines changed <50

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants