Skip to content

Commit 759af61

Browse files
committed
GitHub Actions: migrate from nosetests to unittest
- Replace abandoned nose-py3 with stdlib unittest - Update CI workflow to use 'coverage run -m unittest discover' - Convert all test imports to package-relative imports (from .TLib import *) - Add tests/__init__.py to make tests/ a proper Python package - Fix test_027_warn_shell_globbing_nodes to handle Python 3.12 deprecation warnings - Add 'set -euxo pipefail' to all workflow steps for better error handling - Improve remote Python path detection using site.getsitepackages()
1 parent 0cc8cc2 commit 759af61

21 files changed

Lines changed: 39 additions & 27 deletions

.github/workflows/nosetests.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: ClusterShell nosetests
1+
name: ClusterShell tests
22

33
on: [push, pull_request, merge_group]
44

@@ -21,27 +21,36 @@ jobs:
2121
python-version: ${{ matrix.python-version }}
2222
- name: Install dependencies
2323
run: |
24+
set -euxo pipefail
2425
python -m pip install --upgrade pip
25-
pip install coverage nose-py3 .
26+
pip install coverage .
2627
- name: Allow us to SSH passwordless to localhost
2728
run: |
29+
set -euxo pipefail
2830
chmod og-rw ~
2931
ssh-keygen -f ~/.ssh/id_rsa -N ""
3032
cp ~/.ssh/{id_rsa.pub,authorized_keys}
3133
- name: Avoid ssh "known hosts" warnings
3234
run: |
35+
set -euxo pipefail
3336
printf '%s\n %s\n %s\n' 'Host *' 'StrictHostKeyChecking no' 'LogLevel ERROR' >> ~/.ssh/config
3437
- name: Set Python paths when sshing for gateway tests
3538
run: |
39+
set -euxo pipefail
40+
PYTHON_SITE_PACKAGES=$(python -c "import site; print(site.getsitepackages()[0])")
3641
sed -i "1iexport CLUSTERSHELL_GW_PYTHON_EXECUTABLE=$(which python)" ~/.bashrc
37-
sed -i "2iexport PYTHONPATH=\$PYTHONPATH:$(realpath $pythonLocation/lib/python*/site-packages)" ~/.bashrc
38-
head -2 ~/.bashrc
42+
sed -i "2iexport PYTHONPATH=\$PYTHONPATH:$PYTHON_SITE_PACKAGES" ~/.bashrc
43+
head -3 ~/.bashrc
44+
ssh 127.0.0.2 'python -c "import ClusterShell; print(ClusterShell.__file__)"'
3945
- name: Install pdsh to test WorkerPdsh
4046
run: |
47+
set -euxo pipefail
48+
sudo apt-get update
4149
sudo apt-get -y install pdsh
4250
sudo sh -c 'echo ssh > /etc/pdsh/rcmd_default'
4351
- name: Add tests/bin to remote PATH
4452
run: |
53+
set -euxo pipefail
4554
sed -i "1iexport PATH=$PWD/tests/bin:\$PATH" ~/.bashrc
4655
head -1 ~/.bashrc
4756
ssh 127.0.0.2 which hostname
@@ -78,9 +87,11 @@ jobs:
7887
- name: Run tests
7988
id: tests
8089
run: |
90+
set -euxo pipefail
8191
python --version
8292
export CLUSTERSHELL_GW_PYTHON_EXECUTABLE=$(which python)
83-
nosetests -v --all-modules --with-coverage --cover-tests --cover-erase --cover-package=ClusterShell tests
93+
coverage run --branch --source=ClusterShell -m unittest discover -v -s tests -p '*Test.py' -t .
94+
coverage report -m
8495
- name: Post to Slack (end)
8596
if: always()
8697
continue-on-error: true

tests/CLIClubakTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from textwrap import dedent
88
import unittest
99

10-
from TLib import *
10+
from .TLib import *
1111
from ClusterShell.CLI.Clubak import main
1212

1313
from ClusterShell.NodeSet import set_std_group_resolver, \

tests/CLIClushTest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from subprocess import Popen, PIPE
2222

23-
from TLib import *
23+
from .TLib import *
2424
import ClusterShell.CLI.Clush
2525
from ClusterShell.CLI.Clush import main
2626
from ClusterShell.NodeSet import NodeSet
@@ -443,10 +443,11 @@ def test_027_warn_shell_globbing_nodes(self):
443443
curdir = os.getcwd()
444444
try:
445445
os.chdir(tdir.name)
446-
s = "Warning: using '-w %s' and local path '%s' exists, was it " \
447-
"expanded by the shell?\n" % (HOSTNAME, HOSTNAME)
446+
s = b"Warning: using '-w %s' and local path '%s' exists, was it " \
447+
b"expanded by the shell?\n" % (HOSTNAME.encode(), HOSTNAME.encode())
448+
# Use regex to match start of stderr, allowing for additional warnings
448449
self._clush_t(["-w", HOSTNAME, "echo", "ok"], None,
449-
self.output_ok, 0, s.encode())
450+
self.output_ok, 0, re.compile(re.escape(s)))
450451
finally:
451452
os.chdir(curdir)
452453
tfile.close()

tests/CLIConfigTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from textwrap import dedent
1111
import unittest
1212

13-
from TLib import *
13+
from .TLib import *
1414

1515
from ClusterShell.CLI.Clush import set_fdlimit
1616
from ClusterShell.CLI.Config import ClushConfig, ClushConfigError

tests/CLINodesetTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from textwrap import dedent
99
import unittest
1010

11-
from TLib import *
11+
from .TLib import *
1212
from ClusterShell.CLI.Nodeset import main
1313

1414
from ClusterShell.NodeUtils import GroupResolverConfig

tests/DefaultsTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from textwrap import dedent
1111
import unittest
1212

13-
from TLib import make_temp_file, make_temp_dir
13+
from .TLib import make_temp_file, make_temp_dir
1414

1515
from ClusterShell.Defaults import Defaults, _task_print_debug
1616

tests/MisusageTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import unittest
77

8-
from TLib import HOSTNAME
8+
from .TLib import HOSTNAME
99
from ClusterShell.Event import EventHandler
1010
from ClusterShell.Worker.Popen import WorkerPopen
1111
from ClusterShell.Worker.Ssh import WorkerSsh

tests/NodeSetGroupTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from textwrap import dedent
99
import unittest
1010

11-
from TLib import *
11+
from .TLib import *
1212

1313
# Wildcard import for testing purpose
1414
from ClusterShell.NodeSet import *

tests/TaskDistantMixin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import unittest
88
import warnings
99

10-
from TLib import HOSTNAME, make_temp_filename, make_temp_dir
10+
from .TLib import HOSTNAME, make_temp_filename, make_temp_dir
1111
from ClusterShell.Event import EventHandler
1212
from ClusterShell.Task import *
1313
from ClusterShell.Worker.Ssh import WorkerSsh

tests/TaskDistantPdshMixin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"""Unit test for ClusterShell Task (distant, pdsh worker)"""
55

6-
from TLib import HOSTNAME, make_temp_filename, make_temp_dir
6+
from .TLib import HOSTNAME, make_temp_filename, make_temp_dir
77
from ClusterShell.Event import EventHandler
88
from ClusterShell.Task import *
99
from ClusterShell.Worker.Worker import WorkerBadArgumentError

0 commit comments

Comments
 (0)