提交 e9c0d813 编写于 作者: C Cleber Rosa

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: NCleber Rosa <crosa@redhat.com>
上级 dae3ea22
......@@ -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
......@@ -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
......
# 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)
......
# 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
......
[nosetests]
verbosity=2
cover-erase=1
cover-package=avocado
with-xunit=1
xunit-file=xunit.xml
with-xcoverage=1
xcoverage-file=coverage.xml
......@@ -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}
#!/bin/bash
echo "Cleaning up coverage and running 'selftests/all'"
./selftests/run --with-coverage --cover-package=avocado --cover-erase selftests/all
exit $?
......@@ -3,75 +3,29 @@
__author__ = 'Lucas Meneghel Rodrigues <lmr@redhat.com>'
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())
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册