Skip to content

Commit 4fefe54

Browse files
committed
Making datastore system test use env. at runtime rather than import time.
1 parent b13d03d commit 4fefe54

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

scripts/datastore_emulator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525

2626
from gcloud.environment_vars import GCD_DATASET
2727
from gcloud.environment_vars import GCD_HOST
28+
from system_tests.run_system_test import run_module_tests
2829

2930

3031
_START_CMD = ('gcloud', 'beta', 'emulators', 'datastore', 'start')
3132
_ENV_INIT_CMD = ('gcloud', 'beta', 'emulators', 'datastore', 'env-init')
32-
_HOST_VAR_NAME = 'DATASTORE_HOST'
3333
_DATASET_PREFIX = 'export ' + GCD_DATASET + '='
3434
_HOST_LINE_PREFIX = 'export ' + GCD_HOST + '='
3535

@@ -50,8 +50,6 @@ def main():
5050
os.environ[GCD_DATASET] = dataset
5151
os.environ[GCD_HOST] = host
5252
os.environ['GCLOUD_NO_PRINT'] = 'true'
53-
# Delay import until after environment variables are set.
54-
from system_tests.run_system_test import run_module_tests
5553
run_module_tests('datastore',
5654
ignore_requirements=True)
5755
finally:

system_tests/datastore.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232
from system_tests.system_test_utils import EmulatorCreds
3333

3434

35-
# Isolated namespace so concurrent test runs don't collide.
36-
TEST_NAMESPACE = 'ns%d' % (1000 * time.time(),)
37-
EMULATOR_DATASET = os.getenv(GCD_DATASET)
38-
39-
4035
class Config(object):
4136
"""Run-time configuration to be modified at set-up.
4237
@@ -56,14 +51,17 @@ def clone_client(client):
5651

5752

5853
def setUpModule():
59-
if EMULATOR_DATASET is None:
54+
emulator_dataset = os.getenv(GCD_DATASET)
55+
# Isolated namespace so concurrent test runs don't collide.
56+
test_namespace = 'ns%d' % (1000 * time.time(),)
57+
if emulator_dataset is None:
6058
client_mod.DATASET = TESTS_DATASET
61-
Config.CLIENT = datastore.Client(namespace=TEST_NAMESPACE)
59+
Config.CLIENT = datastore.Client(namespace=test_namespace)
6260
else:
6361
credentials = EmulatorCreds()
6462
http = httplib2.Http() # Un-authorized.
65-
Config.CLIENT = datastore.Client(project=EMULATOR_DATASET,
66-
namespace=TEST_NAMESPACE,
63+
Config.CLIENT = datastore.Client(project=emulator_dataset,
64+
namespace=test_namespace,
6765
credentials=credentials,
6866
http=http)
6967

@@ -209,11 +207,11 @@ def setUpClass(cls):
209207
cls.CLIENT = clone_client(Config.CLIENT)
210208
# Remove the namespace from the cloned client, since these
211209
# query tests rely on the entities to be already stored and indexed,
212-
# hence ``TEST_NAMESPACE`` set at runtime can't be used.
210+
# hence ``test_namespace`` set at runtime can't be used.
213211
cls.CLIENT.namespace = None
214212

215213
# In the emulator, re-populating the datastore is cheap.
216-
if EMULATOR_DATASET is not None:
214+
if os.getenv(GCD_DATASET) is not None:
217215
# Populate the datastore with the cloned client.
218216
populate_datastore.add_characters(client=cls.CLIENT)
219217

@@ -224,7 +222,7 @@ def setUpClass(cls):
224222
@classmethod
225223
def tearDownClass(cls):
226224
# In the emulator, destroy the query entities.
227-
if EMULATOR_DATASET is not None:
225+
if os.getenv(GCD_DATASET) is not None:
228226
# Use the client for this test instead of the global.
229227
clear_datastore.remove_all_entities(client=cls.CLIENT)
230228

0 commit comments

Comments
 (0)