googleapis / googleapis/google-cloud-python

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

Đang mở Phù hợp với người mới
#17,759 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
auth effort: low priority: p3 testing type: bug
Ngôn ngữ chính
Python
Star
5.4k
Fork
1.8k
Merge trung bình
3 ngày 4 giờ
Pull request đã merge (30 ngày)
122

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
testing
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
84/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.