-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathruntests.py
executable file
·97 lines (68 loc) · 2.64 KB
/
runtests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; specifically version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: 2014 Red Hat
# Author: Lucas Meneghel Rodrigues <[email protected]>
__author__ = 'Lucas Meneghel Rodrigues <[email protected]>'
import logging
import os
import sys
from nose.selector import Selector
from nose.plugins import Plugin
from nose.plugins.attrib import AttributeSelector
from nose.plugins.xunit import Xunit
from nose.plugins.cover import Coverage
import nose
logger = logging.getLogger(__name__)
class AutotestClientTestSelector(Selector):
def wantDirectory(self, dirname):
return True
def wantModule(self, module):
return True
def wantFile(self, filename):
if not filename.endswith('_unittest.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 AutotestClientTestRunner(Plugin):
enabled = True
name = 'autotest_client_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("--autotest-client-skip-tests",
dest="skip_tests",
default=[],
help='A space separated list of tests to skip')
def prepareTestLoader(self, loader):
loader.selector = AutotestClientTestSelector(loader.config)
def run_test():
nose.main(addplugins=[AutotestClientTestRunner(),
AttributeSelector(),
Xunit(),
Coverage()])
def main():
run_test()
if __name__ == '__main__':
main()