From e9c0d8134fcd185b20e1628d106631275f6e3e14 Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Wed, 2 Sep 2015 17:31:26 -0300 Subject: [PATCH] Selftests: drop nose usage for plain unittest discovery The unittest module, and unittest2 backport on Python 2.6, is capable of finding unittests and running them. So, effectively, we do not need nose at all. This patch removes the dependency on nose, replacing the run script with a version based solely on the unittest module. One change of functionality is that run now looks and runs tests in the standard selftests directories (unit, functional, doc), and does not accept command line arguments. If one wants to run a subset of them, it's pretty easy to just use the unittest module for that: $ python -m unittest discover -s selftests/unit Signed-off-by: Cleber Rosa --- .travis.yml | 4 +- avocado.spec | 2 +- requirements-selftests.txt | 2 - requirements-travis.txt | 1 - selftests/.nose.cfg | 8 ---- selftests/checkall | 2 +- selftests/coverageall | 4 -- selftests/run | 78 ++++++++------------------------------ 8 files changed, 19 insertions(+), 82 deletions(-) delete mode 100644 selftests/.nose.cfg delete mode 100755 selftests/coverageall diff --git a/.travis.yml b/.travis.yml index badcca21..dc73c303 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,4 @@ script: - inspekt style - ./selftests/cyclical_deps avocado - ./selftests/modules_boundaries - - ./selftests/run -v selftests/all/doc - - ./selftests/run -v selftests/all/functional - - ./selftests/run -v selftests/all/unit + - ./selftests/run diff --git a/avocado.spec b/avocado.spec index 64b1086f..4e5f1ee3 100644 --- a/avocado.spec +++ b/avocado.spec @@ -8,7 +8,7 @@ URL: http://avocado-framework.github.io/ Source: avocado-%{version}.tar.gz BuildArch: noarch Requires: python, python-requests, fabric, pyliblzma, libvirt-python, pystache, gdb, gdb-gdbserver -BuildRequires: python2-devel, python-docutils, python-nose, python-mock +BuildRequires: python2-devel, python-docutils, python-mock %if 0%{?el6} Requires: PyYAML diff --git a/requirements-selftests.txt b/requirements-selftests.txt index 9d5471b8..9673f2fa 100644 --- a/requirements-selftests.txt +++ b/requirements-selftests.txt @@ -1,8 +1,6 @@ # Avocado test requirements # Setuptools setuptools>=18.0.0 -# nose (selftests) -nose>=1.3.0 # sphinx (doc build test) Sphinx>=1.3b1 # flexmock (some unittests use it) diff --git a/requirements-travis.txt b/requirements-travis.txt index cd855e23..6c50b683 100644 --- a/requirements-travis.txt +++ b/requirements-travis.txt @@ -1,6 +1,5 @@ # All pip installable requirements pinned for Travis CI fabric==1.10.0 -nose==1.3.4 pystache==0.5.4 Sphinx==1.3b1 flexmock==0.9.7 diff --git a/selftests/.nose.cfg b/selftests/.nose.cfg deleted file mode 100644 index 139f4a0b..00000000 --- a/selftests/.nose.cfg +++ /dev/null @@ -1,8 +0,0 @@ -[nosetests] -verbosity=2 -cover-erase=1 -cover-package=avocado -with-xunit=1 -xunit-file=xunit.xml -with-xcoverage=1 -xcoverage-file=coverage.xml diff --git a/selftests/checkall b/selftests/checkall index 785d731a..832e74f9 100755 --- a/selftests/checkall +++ b/selftests/checkall @@ -15,5 +15,5 @@ run_rc 'inspekt style' echo "" run_rc 'selftests/modules_boundaries' echo "" -run_rc 'selftests/run selftests/all' +run_rc 'selftests/run' exit ${GR} diff --git a/selftests/coverageall b/selftests/coverageall deleted file mode 100755 index c2e6e6b1..00000000 --- a/selftests/coverageall +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -echo "Cleaning up coverage and running 'selftests/all'" -./selftests/run --with-coverage --cover-package=avocado --cover-erase selftests/all -exit $? diff --git a/selftests/run b/selftests/run index a7474cf5..2b48d39f 100755 --- a/selftests/run +++ b/selftests/run @@ -3,75 +3,29 @@ __author__ = 'Lucas Meneghel Rodrigues ' -import logging import os import sys +import logging -from nose.selector import Selector -from nose.plugins import Plugin -from nose.plugins.attrib import AttributeSelector -import nose +if sys.version_info[:2] == (2, 6): + import unittest2 as unittest +else: + import unittest logger = logging.getLogger(__name__) -class AvocadoTestSelector(Selector): - - def wantDirectory(self, dirname): - return True - - def wantModule(self, module): - return True - - def wantFile(self, filename): - if not filename.endswith('.py'): - return False - - skip_tests = [] - if self.config.options.skip_tests: - skip_tests = self.config.options.skip_tests.split() - - if os.path.basename(filename)[:-3] in skip_tests: - logger.debug('Skipping test: %s' % filename) - return False - - if self.config.options.debug: - logger.debug('Adding %s as a valid test' % filename) - - return True - - -class AvocadoTestRunner(Plugin): - - enabled = True - name = 'avocado_test_runner' - - def configure(self, options, config): - self.result_stream = sys.stdout - - config.logStream = self.result_stream - self.testrunner = nose.core.TextTestRunner(stream=self.result_stream, - descriptions=True, - verbosity=2, - config=config) - - def options(self, parser, env): - parser.add_option("--avocado-skip-tests", - dest="skip_tests", - default=[], - help='A space separated list of tests to skip') - - def prepareTestLoader(self, loader): - loader.selector = AvocadoTestSelector(loader.config) +def test_suite(): + suite = unittest.TestSuite() + loader = unittest.TestLoader() + selftests_dir = os.path.dirname(os.path.abspath(__file__)) + basedir = os.path.dirname(selftests_dir) + for section in ('unit', 'functional', 'doc'): + suite.addTests(loader.discover(start_dir=os.path.join(selftests_dir, section), + top_level_dir=basedir)) + return suite if __name__ == '__main__': - if 'addplugins' in nose.main.__init__.func_code.co_varnames: - nose.main(addplugins=[AvocadoTestRunner(), - AttributeSelector()]) - elif 'plugins' in nose.main.__init__.func_code.co_varnames: - nose.main(plugins=[AvocadoTestRunner(), - AttributeSelector()]) - else: - print("Unsupported nose API, can't proceed with testing...") - sys.exit(1) + runner = unittest.TextTestRunner() + runner.run(test_suite()) -- GitLab