28
28
TEST_PATH Path to package containing test modules"""
29
29
30
30
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
+
35
+ Not all Google packages are inside namespaced packages, which means
36
+ there might be another named `google` on the path, and simply appending
37
+ the App Engine SDK to the path will not work since the other package
38
+ will get discovered and used first. This ugly hack emulates namespace
39
+ packages by first searching if a `google` package already exists by
40
+ importing it, and if so appending to its path, otherwise it just
41
+ inserts it into the import path by itself.
42
+ """
43
+ try :
44
+ import google
45
+ google .__path__ .append ("{0}/google" .format (path ))
46
+ except ImportError :
47
+ sys .path .insert (0 , path )
48
+
49
+
31
50
def main (sdk_path , test_path ):
32
51
# If the sdk path points to a google cloud sdk installation
33
52
# then we should alter it to point to the GAE platform location.
53
+
34
54
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' ))
55
+ append_or_insert_path (
56
+ os .path .join (sdk_path , 'platform/google_appengine' ))
36
57
else :
37
- sys . path . insert ( 0 , sdk_path )
58
+ append_or_insert_path ( sdk_path )
38
59
39
60
# Ensure that the google.appengine.* packages are available
40
61
# in tests as well as all bundled third-party packages.
@@ -51,7 +72,7 @@ def main(sdk_path, test_path):
51
72
print "Note: unable to import appengine_config."
52
73
53
74
# Discover and run tests.
54
- suite = unittest .loader .TestLoader ().discover (test_path )
75
+ suite = unittest .loader .TestLoader ().discover (test_path , "*_test.py" )
55
76
unittest .TextTestRunner (verbosity = 2 ).run (suite )
56
77
57
78
0 commit comments