Skip to content

Commit 38386df

Browse files
committed
Fix running individual test files when ninja is not installed
The code in testing/framework/TestSCons.py attempted to handle an ImportError if ninja is not available. However, when running individual test files from the scons/test/ directory, this directory is included as the first entry in sys.path. When this happens, the `import ninja` statement succeeds, finding the scons/test/ninja/ directory and treating it as a package. This results in an AttributeError being thrown later attempting to access `ninja.BIN_DIR`, rather than an ImportError. I have confirmed that this change now allows `./runtest.py test/Help.py` to succeed, even when ninja is not installed.
1 parent a6abb0f commit 38386df

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

testing/framework/TestSCons.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,17 @@
107107
dll_ = dll_prefix
108108

109109
try:
110+
# Note: if the ninja python package is not installed, this import statement can end
111+
# up finding the scons/test/ninja directory instead, and successfully importing
112+
# that directory as an implicit namespace package. Therefore if ninja is
113+
# unavailable, we may not get an ImportError here, but can instead get an
114+
# AttributeError when attempting to access ninja.BIN_DIR below. This happens
115+
# when running individual test files in the test/ directory, since the test/
116+
# directory will then be listed as the first entry in sys.path
110117
import ninja
111118

112119
NINJA_BINARY = os.path.abspath(os.path.join(ninja.BIN_DIR, 'ninja' + _exe))
113-
except ImportError:
120+
except (ImportError, AttributeError):
114121
NINJA_BINARY = None
115122

116123
if sys.platform == 'cygwin':

0 commit comments

Comments
 (0)