Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Unit tests must not depend on environment variables #416

Description

@tseaver

E.g.,:

$ env | grep GOOGLE ||echo NO
NO
$ nox -re unit-3.9 -- -x
_______________ Test_Blob.test_download_as_byte_w_custom_timeout _______________
self = <tests.unit.test_blob.Test_Blob testMethod=test_download_as_byte_w_custom_timeout>
def test_download_as_byte_w_custom_timeout(self):
> self._download_as_bytes_helper(raw_download=False, timeout=9.58)
tests/unit/test_blob.py:1714: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/unit/test_blob.py:1557: in _download_as_bytes_helper
client = self._make_client()
tests/unit/test_blob.py:59: in _make_client
return Client(*args, **kw)
google/cloud/storage/client.py:122: in __init__
super(Client, self).__init__(
.nox/unit-3-9/lib/python3.9/site-packages/google/cloud/client.py:277: in __init__
_ClientProjectMixin.__init__(self, project=project, credentials=credentials)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <google.cloud.storage.client.Client object at 0x7fb9f31415b0>
project = None, credentials = None
def __init__(self, project=None, credentials=None):
# This test duplicates the one from `google.auth.default`, but earlier,# for backward compatibility: we want the environment variable to# override any project set on the credentials. See:# https://github.com/googleapis/python-cloud-core/issues/27if project is None:
project = os.getenv(
environment_vars.PROJECT,
os.getenv(environment_vars.LEGACY_PROJECT),
)
# Project set on explicit credentials overrides discovery from# SDK / GAE / GCE.if project is None and credentials is not None:
project = getattr(credentials, "project_id", None)
if project is None:
project = self._determine_default(project)
if project is None:
> raise EnvironmentError(
"Project was not passed and could not be ""determined from the environment."
)
E OSError: Project was not passed and could not be determined from the environment.
.nox/unit-3-9/lib/python3.9/site-packages/google/cloud/client.py:228: OSError

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/python-storage API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: processA process-related concern. May include testing, release, or the like.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions