googleapis / googleapis/google-cloud-python

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

Aperta Adatta ai principianti
#17,759 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
auth effort: low priority: p3 testing type: bug
Lingua principale
Python
Stelle
5.4k
Fork
1.8k
Merge medio
3g 4h
PR unite (30g)
122

Descrizione

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`.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
testing
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
84/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.