Skip to content

Commit 91b1041

Browse files
author
Bill Prin
committed
Fix local unit test sample
Fixes discovery pattern Adds some more import path hacks
1 parent a18bc9d commit 91b1041

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

appengine/standard/localtesting/runner.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,25 @@
2828
TEST_PATH Path to package containing test modules"""
2929

3030

31+
def append_or_insert_path(path):
32+
"""Adds GAE path to system path, or appends it to the google path
33+
if that already exists."""
34+
try:
35+
import google
36+
google.__path__.append("{0}/google".format(path))
37+
except ImportError:
38+
sys.path.insert(0, path)
39+
40+
3141
def main(sdk_path, test_path):
3242
# If the sdk path points to a google cloud sdk installation
3343
# then we should alter it to point to the GAE platform location.
44+
3445
if os.path.exists(os.path.join(sdk_path, 'platform/google_appengine')):
35-
sys.path.insert(0, os.path.join(sdk_path, 'platform/google_appengine'))
46+
append_or_insert_path(
47+
os.path.join(sdk_path, 'platform/google_appengine'))
3648
else:
37-
sys.path.insert(0, sdk_path)
49+
append_or_insert_path(sdk_path)
3850

3951
# Ensure that the google.appengine.* packages are available
4052
# in tests as well as all bundled third-party packages.
@@ -51,7 +63,7 @@ def main(sdk_path, test_path):
5163
print "Note: unable to import appengine_config."
5264

5365
# Discover and run tests.
54-
suite = unittest.loader.TestLoader().discover(test_path)
66+
suite = unittest.loader.TestLoader().discover(test_path, "*_test.py")
5567
unittest.TextTestRunner(verbosity=2).run(suite)
5668

5769

0 commit comments

Comments
 (0)