google-auth: Tests in test__default.py fail if GOOGLE_CLOUD_PROJECT is set in the local environment

Open Beginner friendly
#17,759 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
testing

Research direction

Start in tests/test__default.py with test_default_early_out and test_default_gdch_service_account_credentials, then inspect how google.auth.default() reads GOOGLE_CLOUD_PROJECT. Run those tests with the environment variable set and isolate the project-related variables using pytest’s monkeypatch support. Done means the tests pass both with and without GOOGLE_CLOUD_PROJECT in the local environment.

Written by the indexing model from the issue text.

Description

auth effort: low priority: p3 testing type: bug

If you run the test suite locally with GOOGLE_CLOUD_PROJECT set in your environment, several tests in tests/test__default.py (such as test_default_early_out and test_default_gdch_service_account_credentials) will fail.

The google.auth.default() function reads os.environ.get("GOOGLE_CLOUD_PROJECT") to determine the project ID. Because os.environ isn't fully mocked or cleared in these tests, the local environment variable takes precedence over the mocked project_id sentinels, resulting in assertion failures.

To fix this, we should properly isolate the tests from the local environment by clearing or mocking the project-related environment variables (e.g., using pytest's monkeypatch.delenv) inside test__default.py.

Dominant language
Python
Stars
5.4k
Forks
1.8k
Avg merge
1d 17h
Merged PRs (30d)
93

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleapis/google-cloud-python

All issues in googleapis/google-cloud-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.