selftest: Always set PYTHON to something sensible (if it isn't set)
authorNoel Power <noel.power@suse.com>
Mon, 26 Nov 2018 14:55:02 +0000 (14:55 +0000)
committerNoel Power <npower@samba.org>
Mon, 10 Dec 2018 09:38:25 +0000 (10:38 +0100)
Lots of test scripts need to run with the correct version
of python. With the correct shebang the script should run with the
correct version, the problem is that not all scripts are part
of the installation, some scripts are part of the source code,
and the shebang is not dynamically generated as yet.
It is safer if we are somewhat version neutral at the moment and
ignore the shebang and always run scripts from the test environment
with the python version (determined by PYTHON env variable) If this
env variable isn't set then set it according to the python version
that is running the tests

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
selftest/wscript

index ce1e117cbdcdba64599bcfb445338f3c40b48507..b7eec2c2605e8d74020da6c770d2ae9a73903b41 100644 (file)
@@ -121,6 +121,21 @@ def cmd_testonly(opt):
     env.TESTS  = Options.options.TESTS
 
     env.SUBUNIT_FORMATTER = os.getenv('SUBUNIT_FORMATTER')
+
+    # Lots of test scripts need to run with the correct version
+    # of python. With the correct shebang the script should run with the
+    # correct version, the problem is that not all scripts are part
+    # of the installation, some scripts are part of the source code,
+    # and the shebang is not dynamically generated as yet.
+    # It is safer if we are somewhat version neutral at the moment and
+    # ignore the shebang and always run scripts from the test environment
+    # with the python version (determined by PYTHON env variable) If this
+    # env variable isn't set then set it according to the python version
+    # that is running the tests
+    if not os.getenv('PYTHON', None):
+        from sys import executable as exe
+        os.environ['PYTHON'] = os.path.basename(exe)
+
     if not env.SUBUNIT_FORMATTER:
         if Options.options.PERF_TEST:
             env.SUBUNIT_FORMATTER = '${PYTHON} -u ${srcdir}/selftest/format-subunit-json --prefix=${SELFTEST_PREFIX}'