~0x44/nova/bug838466

468.3.8 by Andy Smith
merged from trunk
1
#!/usr/bin/env python
1 by Jesse Andrews
initial commit
2
# vim: tabstop=4 shiftwidth=4 softtabstop=4
114 by Devin Carlen
Updated licenses
3
4
# Copyright 2010 United States Government as represented by the
3.1.9 by Vishvananda Ishaya
Removed trailing whitespace from header
5
# Administrator of the National Aeronautics and Space Administration.
114 by Devin Carlen
Updated licenses
6
# All Rights Reserved.
7
#
468.3.8 by Andy Smith
merged from trunk
8
#    Licensed under the Apache License, Version 2.0 (the "License");
9
#    you may not use this file except in compliance with the License.
10
#    You may obtain a copy of the License at
114 by Devin Carlen
Updated licenses
11
#
468.3.8 by Andy Smith
merged from trunk
12
#        http://www.apache.org/licenses/LICENSE-2.0
1 by Jesse Andrews
initial commit
13
#
14
#    Unless required by applicable law or agreed to in writing, software
468.3.8 by Andy Smith
merged from trunk
15
#    distributed under the License is distributed on an "AS IS" BASIS,
16
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
#    See the License for the specific language governing permissions and
18
#    limitations under the License.
19
715.2.1 by termie
allow users to omit 'nova.tests' with run_tests
20
"""Unittest runner for Nova.
21
22
To run all tests
23
    python run_tests.py
24
25
To run a single test:
26
    python run_tests.py test_compute:ComputeTestCase.test_run_terminate
27
28
To run a single test module:
29
    python run_tests.py test_compute
30
31
    or
32
33
    python run_tests.py api.test_wsgi
34
35
"""
36
556.5.7 by Andy Smith
merge from upstream and fix small issues
37
import gettext
140.5.1 by Jay Pipes
Adds a flag to redirect STDERR when running run_tests.py. Defaults to a truncate-on-write logfile named run_tests.err.log. Adds ignore rule for generated errlog file.
38
import os
468.3.8 by Andy Smith
merged from trunk
39
import unittest
1 by Jesse Andrews
initial commit
40
import sys
41
468.3.8 by Andy Smith
merged from trunk
42
from nose import config
43
from nose import result
44
from nose import core
45
706.2.15 by Vishvananda Ishaya
switch to explicit call to logging.setup()
46
from nova import log as logging
706.2.18 by Vishvananda Ishaya
fixed newline and moved import fake_flags into run_tests where it makes more sense
47
from nova.tests import fake_flags
48
468.3.8 by Andy Smith
merged from trunk
49
50
class NovaTestResult(result.TextTestResult):
51
    def __init__(self, *args, **kw):
52
        result.TextTestResult.__init__(self, *args, **kw)
53
        self._last_case = None
54
55
    def getDescription(self, test):
56
        return str(test)
57
58
    def startTest(self, test):
59
        unittest.TestResult.startTest(self, test)
60
        current_case = test.test.__class__.__name__
61
62
        if self.showAll:
63
            if current_case != self._last_case:
64
                self.stream.writeln(current_case)
65
                self._last_case = current_case
66
67
            self.stream.write(
68
                '    %s' % str(test.test._testMethodName).ljust(60))
69
            self.stream.flush()
70
71
72
class NovaTestRunner(core.TextTestRunner):
73
    def _makeResult(self):
74
        return NovaTestResult(self.stream,
75
                              self.descriptions,
76
                              self.verbosity,
77
                              self.config)
238.1.1 by andy
rather comprehensive style fixes
78
140.5.1 by Jay Pipes
Adds a flag to redirect STDERR when running run_tests.py. Defaults to a truncate-on-write logfile named run_tests.err.log. Adds ignore rule for generated errlog file.
79
1 by Jesse Andrews
initial commit
80
if __name__ == '__main__':
706.2.15 by Vishvananda Ishaya
switch to explicit call to logging.setup()
81
    logging.setup()
715.2.1 by termie
allow users to omit 'nova.tests' with run_tests
82
    # If any argument looks like a test name but doesn't have "nova.tests" in
83
    # front of it, automatically add that so we don't have to type as much
84
    argv = []
85
    for x in sys.argv:
86
        if x.startswith('test_'):
87
            argv.append('nova.tests.%s' % x)
88
        else:
89
            argv.append(x)
90
468.3.8 by Andy Smith
merged from trunk
91
    c = config.Config(stream=sys.stdout,
92
                      env=os.environ,
592.1.1 by Soren Hansen
Pass a PluginManager to nose.config.Config(). This lets us use plugins like coverage, xcoverage, etc.
93
                      verbosity=3,
94
                      plugins=core.DefaultPluginManager())
468.3.8 by Andy Smith
merged from trunk
95
96
    runner = NovaTestRunner(stream=c.stream,
97
                            verbosity=c.verbosity,
98
                            config=c)
715.2.1 by termie
allow users to omit 'nova.tests' with run_tests
99
    sys.exit(not core.run(config=c, testRunner=runner, argv=argv))