Skip to content

Commit 96e9df9

Browse files
tswastparthea
authored andcommitted
TST: Load integration test creds from env vars (googleapis#29)
Load the credentials for integration tests from environment variables. This will make it easier to run the integration tests locally. Also adds instructions for running the integrations tests locally. Closes GH#27.
1 parent 22fe0de commit 96e9df9

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

docs/source/contributing.rst

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,14 @@ Running Google BigQuery Integration Tests
230230
You will need to create a Google BigQuery private key in JSON format in
231231
order to run Google BigQuery integration tests on your local machine and
232232
on Travis-CI. The first step is to create a `service account
233-
<https://console.developers.google.com/iam-admin/serviceaccounts/>`__.
233+
<https://console.cloud.google.com/iam-admin/serviceaccounts/>`__.
234+
235+
To run the integration tests locally, set the following environment variables
236+
before running ``pytest``:
237+
238+
#. ``GBQ_PROJECT_ID`` with the value being the ID of your BigQuery project.
239+
#. ``GBQ_GOOGLE_APPLICATION_CREDENTIALS`` with the value being the *path* to
240+
the JSON key that you downloaded for your service account.
234241

235242
Integration tests are skipped in pull requests because the credentials that
236243
are required for running Google BigQuery integration tests are
@@ -248,8 +255,8 @@ gbq integration tests on a forked repository:
248255

249256
- ``GBQ_PROJECT_ID`` with the value being the ID of your BigQuery project.
250257

251-
- ``SERVICE_ACCOUNT_KEY`` with the value being the contents of the JSON key
252-
that you downloaded for your service account. Use single quotes around
258+
- ``SERVICE_ACCOUNT_KEY`` with the value being the *contents* of the JSON
259+
key that you downloaded for your service account. Use single quotes around
253260
your JSON key to ensure that it is treated as a string.
254261

255262
For both environment variables, keep the "Display value in build log" option

pandas_gbq/tests/test_gbq.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
import pandas.util.testing as tm
2020
from pandas.compat.numpy import np_datetime64_compat
2121

22-
PROJECT_ID = None
23-
PRIVATE_KEY_JSON_PATH = None
24-
PRIVATE_KEY_JSON_CONTENTS = None
2522

2623
TABLE_ID = 'new_test'
2724

@@ -66,27 +63,24 @@ def _get_dataset_prefix_random():
6663

6764

6865
def _get_project_id():
69-
if _in_travis_environment():
70-
return os.environ.get('GBQ_PROJECT_ID')
71-
else:
72-
return PROJECT_ID
66+
return os.environ.get('GBQ_PROJECT_ID')
7367

7468

7569
def _get_private_key_path():
7670
if _in_travis_environment():
7771
return os.path.join(*[os.environ.get('TRAVIS_BUILD_DIR'), 'ci',
7872
'travis_gbq.json'])
7973
else:
80-
return PRIVATE_KEY_JSON_PATH
74+
return os.environ.get('GBQ_GOOGLE_APPLICATION_CREDENTIALS')
8175

8276

8377
def _get_private_key_contents():
84-
if _in_travis_environment():
85-
with open(os.path.join(*[os.environ.get('TRAVIS_BUILD_DIR'), 'ci',
86-
'travis_gbq.json'])) as f:
87-
return f.read()
88-
else:
89-
return PRIVATE_KEY_JSON_CONTENTS
78+
key_path = _get_private_key_path()
79+
if key_path is None:
80+
return None
81+
82+
with open(key_path) as f:
83+
return f.read()
9084

9185

9286
def _test_imports():

0 commit comments

Comments
 (0)