#!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = 'Lucas Meneghel Rodrigues ' import logging import os import sys from nose.selector import Selector from nose.plugins import Plugin from nose.plugins.attrib import AttributeSelector import nose 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) 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)