Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests must not depend on environment variables #416

Closed
tseaver opened this issue Apr 20, 2021 · 1 comment · Fixed by #459
Closed

Unit tests must not depend on environment variables #416

tseaver opened this issue Apr 20, 2021 · 1 comment · Fixed by #459
Assignees
Labels
api: storage Issues related to the googleapis/python-storage API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: process A process-related concern. May include testing, release, or the like.

Comments

@tseaver
Copy link
Contributor

tseaver commented Apr 20, 2021

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/27
        if 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
@tseaver tseaver added type: process A process-related concern. May include testing, release, or the like. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels Apr 20, 2021
@tseaver tseaver self-assigned this Apr 20, 2021
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/python-storage API. label Apr 20, 2021
@tseaver
Copy link
Contributor Author

tseaver commented May 20, 2021

tseaver added a commit that referenced this issue Jun 8, 2021
Also, adjust 'Bucket.get_upload_policy' to use credentials from the client,
rather than its connection.

Remove last uses of '_Client' and '_Connection' shims:  use a mocked
client instead.

Toward #416.
tseaver added a commit that referenced this issue Jun 8, 2021
tseaver added a commit that referenced this issue Jun 8, 2021
tseaver added a commit that referenced this issue Jun 9, 2021
Adjust 'Bucket.get_upload_policy' to use credentials from the client,
rather than its connection.

Closes #416.
cojenco pushed a commit to cojenco/python-storage that referenced this issue Oct 13, 2021
Adjust 'Bucket.get_upload_policy' to use credentials from the client,
rather than its connection.

Closes googleapis#416.
cojenco pushed a commit to cojenco/python-storage that referenced this issue Oct 13, 2021
Adjust 'Bucket.get_upload_policy' to use credentials from the client,
rather than its connection.

Closes googleapis#416.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/python-storage API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: process A process-related concern. May include testing, release, or the like.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant