Subject: [bug#30556][PATCH] Python tests should run with multiple python versions

From: Bogdan <[email-masked]>
Date: Sun, 26 Mar 2023 13:21:45 +0200

Hi.

  I have both Python v2 and v3 installed on my system. The tests shown 
in the provided error log pass for me, in all cases:

- no version - defaults to 3.9.8

make check TESTS='t/nobase-python.sh t/py-compile-basic.sh 
t/py-compile-basedir.sh t/py-compile-destdir.sh 
t/py-compile-option-terminate.sh t/python3.sh t/python10.sh 
t/python12.sh '

- explicit v2 (2.7.18):

PYTHON=python2 make check TESTS='t/nobase-python.sh 
t/py-compile-basic.sh t/py-compile-basedir.sh t/py-compile-destdir.sh 
t/py-compile-option-terminate.sh t/python3.sh t/python10.sh 
t/python12.sh '

- explicit v3:

PYTHON=python3 make check TESTS='t/nobase-python.sh 
t/py-compile-basic.sh t/py-compile-basedir.sh t/py-compile-destdir.sh 
t/py-compile-option-terminate.sh t/python3.sh t/python10.sh 
t/python12.sh '

I guess this got fixed in the repository since the defect was 
reported. Some of the tests touch the "uninstall" target and that 
certainly was changed.

My Automake version:
- branch: master
- last commit ID: 0901ccdd0cb21bfa3911a2668615e388fef94426
- last commit date: Wed Mar 1 15:03:30 2023 -0800

Actually, I could fix t/python-prefix.sh to work with Python v2 and 
t/python-virtualenv.sh to work at all (didn't work by default for me). 
Patch attached. Now all tests with "py" in the name pass on my system 
(both with v2 and v3). I assume that Automake, 'make install' and 
'make uninstall' do their job correctly (and that's most probably 
true) and it's just the tests that were doing wrong.

-- 
Regards - Bogdan ('bogdro') D.                 (GNU/Linux & FreeDOS)
X86 assembly (DOS, GNU/Linux):    http://bogdro.evai.pl/index-en.php
Soft(EN): http://bogdro.evai.pl/soft  http://bogdro.evai.pl/soft4asm
www.Xiph.org  www.TorProject.org  www.LibreOffice.org  www.GnuPG.org

From 96da24fbbaf40cb793ac0decd4c398cdb683b4e2 Mon Sep 17 00:00:00 2001
From: Bogdan Drozdowski <>
Date: Sun, 26 Mar 2023 13:15:40 +0200
Subject: [PATCH] Fix Python tests - multiple versions

---
 t/python-prefix.sh     |  6 +++++-
 t/python-virtualenv.sh | 10 ++++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/t/python-prefix.sh b/t/python-prefix.sh
index df15e4300..dab2e9fd5 100644
--- a/t/python-prefix.sh
+++ b/t/python-prefix.sh
@@ -43,7 +43,11 @@ echo-python-exec-prefix:
 	@echo $(PYTHON_EXEC_PREFIX)
 END
 
-py_version=$(python -c 'import sys; print("%u.%u" % sys.version_info[:2])')
+py_exec=$PYTHON
+if test "x$py_exec" = "x"; then
+  py_exec=python
+fi
+py_version=$($py_exec -c 'import sys; print("%u.%u" % sys.version_info[:2])')
 py_inst_site=inst/lib/python$py_version/site-packages
 py_instexec_site=instexec/lib/python$py_version/site-packages
 
diff --git a/t/python-virtualenv.sh b/t/python-virtualenv.sh
index ae5d96ad6..b06964b90 100644
--- a/t/python-virtualenv.sh
+++ b/t/python-virtualenv.sh
@@ -100,6 +100,8 @@ test-run:
 	python -c 'from am_foo import foo_func; assert (foo_func () == 12345)'
 	python -c 'from am_virtenv import old_am; assert (old_am () == "AutoMake")'
 all-local: debug
+get-pyexecdir:
+	@echo $(pyexecdir)
 END
 
 cat > am_foo.py << 'END'
@@ -127,8 +129,8 @@ check_install ()
   py_installed "$py_site"/am_foo.pyc
   py_installed "$py_site"/am_virtenv/__init__.py
   py_installed "$py_site"/am_virtenv/__init__.pyc
-  test -f      "$py_site"/libquux.a
-  test -f      "$py_site"/am_virtenv/libzardoz.a
+  test -f      "$($MAKE get-pyexecdir ${1+"$@"})"/libquux.a
+  test -f      "$($MAKE get-pyexecdir ${1+"$@"})"/am_virtenv/libzardoz.a
 }
 
 check_uninstall ()
@@ -139,8 +141,8 @@ check_uninstall ()
   py_installed --not "$py_site"/am_foo.pyc
   test ! -e          "$py_site"/am_virtenv/__init__.py
   py_installed --not "$py_site"/am_virtenv/__init__.pyc
-  test ! -e          "$py_site"/libquux.a
-  test ! -e          "$py_site"/am_virtenv/libzardoz.a
+  test ! -e          "$($MAKE get-pyexecdir ${1+"$@"})"/libquux.a
+  test ! -e          "$($MAKE get-pyexecdir ${1+"$@"})"/am_virtenv/libzardoz.a
 }
 
 $ACLOCAL
-- 
2.35.1