From ca8d95c243dacb367c0b11c5190d5ec56e402afd Mon Sep 17 00:00:00 2001 From: Jake Hunsaker Date: Wed, 6 Oct 2021 16:53:43 -0400 Subject: [tests] Run unit tests under avocado instead of nose `nose` is no longer maintained, and as of python-3.10 is functionally broken. As such, instead transition to running those tests via avocado, like we do with our integration test suite. The tests themselves do not need much modification, however due to the isolation provided for executing the tests we do need to explicitly set a new PYTHONPATH env var for those executions. This means we still need to run the unit tests as a separate step from the stageone tests. The changes needed are mostly around file paths relative to the pwd where the tests are executed from originally. Additionally, remove the sosreport_pexpect unit test as it is no longer useful in its own right, would need more significant changes to run properly with avocado, and the integration test suite provides better coverage for what it was testing. Closes: #2716 Signed-off-by: Jake Hunsaker --- .cirrus.yml | 14 ++++---------- tests/unittests/plugin_tests.py | 1 + tests/unittests/sosreport_pexpect.py | 36 ------------------------------------ tests/unittests/utilities_tests.py | 3 +-- 4 files changed, 6 insertions(+), 48 deletions(-) delete mode 100644 tests/unittests/sosreport_pexpect.py diff --git a/.cirrus.yml b/.cirrus.yml index c77289d4..f36ec816 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -45,15 +45,6 @@ flake8_task: image: alpine/flake8:latest flake_script: flake8 sos -# nose tests, again on the community cluster -nosetests_task: - alias: nosetests - name: "Nosetests" - container: - image: python:slim - setup_script: pip install nose - nose_script: nosetests -v --with-cover --cover-package=sos tests/unittests - # Run a check on newer upstream python versions to check for possible # breaks/changes in common modules. This is not meant to check any of the actual # collections or archive integrity. @@ -123,10 +114,13 @@ report_stageone_task: dnf -y remove sos fi setup_script: &setup 'pip3 install avocado-framework' + # run the unittests separately as they require a different PYTHONPATH in + # order for the imports to work properly under avocado + unittest_script: PYTHONPATH=. avocado run tests/unittests/ main_script: PYTHONPATH=tests/ avocado run --test-runner=runner -t stageone tests/{cleaner,collect,report,vendor}_tests on_failure: fail_script: &faillogs | - tar cf sos-fail-logs.tar /var/tmp/avocado* + ls -d /var/tmp/avocado* /root/avocado* 2> /dev/null | xargs tar cf sos-fail-logs.tar log_artifacts: path: "sos-fail-logs.tar" diff --git a/tests/unittests/plugin_tests.py b/tests/unittests/plugin_tests.py index 0105e3b8..0dfa243d 100644 --- a/tests/unittests/plugin_tests.py +++ b/tests/unittests/plugin_tests.py @@ -429,6 +429,7 @@ class RegexSubTests(unittest.TestCase): "never_copied", r"^(.*)$", "foobar")) def test_no_replacements(self): + self.mp.sysroot = '/' self.mp.add_copy_spec(j("tail_test.txt")) self.mp.collect() replacements = self.mp.do_file_sub( diff --git a/tests/unittests/sosreport_pexpect.py b/tests/unittests/sosreport_pexpect.py deleted file mode 100644 index 3614fa5b..00000000 --- a/tests/unittests/sosreport_pexpect.py +++ /dev/null @@ -1,36 +0,0 @@ -# This file is part of the sos project: https://github.com/sosreport/sos -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# version 2 of the GNU General Public License. -# -# See the LICENSE file in the source distribution for further information. -import unittest -import pexpect - -from os import kill -from signal import SIGINT - - -class PexpectTest(unittest.TestCase): - def test_plugins_install(self): - sos = pexpect.spawn('/usr/sbin/sosreport -l') - try: - sos.expect('plugin.*does not install, skipping') - except pexpect.EOF: - pass - else: - self.fail("a plugin does not install or sosreport is too slow") - kill(sos.pid, SIGINT) - - def test_batchmode_removes_questions(self): - sos = pexpect.spawn('/usr/sbin/sosreport --batch') - grp = sos.expect('send this file to your support representative.', 15) - self.assertEquals(grp, 0) - kill(sos.pid, SIGINT) - - -if __name__ == '__main__': - unittest.main() - -# vim: set et ts=4 sw=4 : diff --git a/tests/unittests/utilities_tests.py b/tests/unittests/utilities_tests.py index 83a4dc28..19524819 100644 --- a/tests/unittests/utilities_tests.py +++ b/tests/unittests/utilities_tests.py @@ -78,9 +78,8 @@ class ExecutableTest(unittest.TestCase): def test_output_chdir(self): cmd = "/bin/bash -c 'echo $PWD'" result = sos_get_command_output(cmd, chdir=TEST_DIR) - print(result) self.assertEquals(result['status'], 0) - self.assertEquals(result['output'].strip(), TEST_DIR) + self.assertTrue(result['output'].strip().endswith(TEST_DIR)) def test_shell_out(self): self.assertEquals("executed\n", shell_out('echo executed')) -- cgit