From 38386dfaf4e31a16f93dcc7c7387798fe7576334 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Sun, 23 Feb 2025 12:17:44 -0800 Subject: 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. --- testing/framework/TestSCons.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/testing/framework/TestSCons.py b/testing/framework/TestSCons.py index fda32b8..a5ca8a0 100644 --- a/testing/framework/TestSCons.py +++ b/testing/framework/TestSCons.py @@ -107,10 +107,17 @@ _dll = dll_suffix dll_ = dll_prefix try: + # Note: if the ninja python package is not installed, this import statement can end + # up finding the scons/test/ninja directory instead, and successfully importing + # that directory as an implicit namespace package. Therefore if ninja is + # unavailable, we may not get an ImportError here, but can instead get an + # AttributeError when attempting to access ninja.BIN_DIR below. This happens + # when running individual test files in the test/ directory, since the test/ + # directory will then be listed as the first entry in sys.path import ninja NINJA_BINARY = os.path.abspath(os.path.join(ninja.BIN_DIR, 'ninja' + _exe)) -except ImportError: +except (ImportError, AttributeError): NINJA_BINARY = None if sys.platform == 'cygwin': -- cgit v0.12