Search code examples
pythongoogle-sheetspytestgspread

gspread tests giving error "google.auth.exceptions.RefreshError"


I downloaded gspread from github (https://github.com/burnash/gspread). Installed all the necessary packages. Tried running test using gspread$ pytest tests/spreadsheet_test.py

and all the tests failed with similar error

========================================================== ERRORS ==========================================================
_________________________________ ERROR at setup of SpreadsheetTest.test_add_del_worksheet _________________________________

self = <tests.spreadsheet_test.SpreadsheetTest testMethod=test_add_del_worksheet>
client = <gspread.client.BackoffClient object at 0x7f07c002b350>
request = <SubRequest 'init' for <TestCaseFunction test_add_del_worksheet>>

    @pytest.fixture(scope="function", autouse=True)
    def init(self, client, request):
        name = self.get_temporary_spreadsheet_title(request.node.name)
>       SpreadsheetTest.spreadsheet = client.create(name)

tests/spreadsheet_test.py:17: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
gspread/client.py:247: in create
    r = self.request("post", DRIVE_FILES_API_V3_URL, json=payload, params=params)
gspread/client.py:599: in request
    return super().request(*args, **kwargs)
gspread/client.py:80: in request
    response = getattr(self.session, method)(
/usr/lib/python3/dist-packages/requests/sessions.py:635: in post
    return self.request("POST", url, data=data, json=json, **kwargs)
/usr/lib/python3/dist-packages/google/auth/transport/requests.py:218: in request
    self.credentials.refresh(auth_request_with_timeout)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <tests.conftest.DummyCredentials object at 0x7f07bf275a50>
request = functools.partial(<google.auth.transport.requests.Request object at 0x7f07bf276210>, timeout=None)

    @_helpers.copy_docstring(credentials.Credentials)
    def refresh(self, request):
        if (self._refresh_token is None or
                self._token_uri is None or
                self._client_id is None or
                self._client_secret is None):
>           raise exceptions.RefreshError(
                'The credentials do not contain the necessary fields need to '
                'refresh the access token. You must specify refresh_token, '
                'token_uri, client_id, and client_secret.')
E           google.auth.exceptions.RefreshError: The credentials do not contain the necessary fields need to refresh the access token. You must specify refresh_token, token_uri, client_id, and client_secret.

/usr/lib/python3/dist-packages/google/oauth2/credentials.py:128: RefreshError

How to make them pass? I was hoping unittest will run on mint condition code.


Solution

  • It looks like I was missing few required packages.

    Most probably the missing one was pytest-vcr.

    However, I installed few others, so it can be one of them. The other ones I installed are pytest, vcr, google-auth, google-auth-oauthlib.