|
25 | 25 |
|
26 | 26 | import splunklib |
27 | 27 |
|
| 28 | +failed = False |
28 | 29 |
|
29 | 30 | def run_test_suite(): |
30 | 31 | try: |
31 | 32 | import unittest2 as unittest |
32 | 33 | except ImportError: |
33 | 34 | import unittest |
| 35 | + |
| 36 | + def mark_failed(): |
| 37 | + global failed |
| 38 | + failed = True |
| 39 | + |
| 40 | + class _TrackingTextTestResult(unittest._TextTestResult): |
| 41 | + def addError(self, test, err): |
| 42 | + unittest._TextTestResult.addError(self, test, err) |
| 43 | + mark_failed() |
| 44 | + |
| 45 | + def addFailure(self, test, err): |
| 46 | + unittest._TextTestResult.addFailure(self, test, err) |
| 47 | + mark_failed() |
| 48 | + |
| 49 | + class TrackingTextTestRunner(unittest.TextTestRunner): |
| 50 | + def _makeResult(self): |
| 51 | + return _TrackingTextTestResult( |
| 52 | + self.stream, self.descriptions, self.verbosity) |
| 53 | + |
34 | 54 | original_cwd = os.path.abspath(os.getcwd()) |
35 | 55 | os.chdir('tests') |
36 | 56 | suite = unittest.defaultTestLoader.discover('.') |
37 | | - unittest.TextTestRunner().run(suite) |
| 57 | + runner = TrackingTextTestRunner(verbosity=2) |
| 58 | + runner.run(suite) |
38 | 59 | os.chdir(original_cwd) |
| 60 | + |
| 61 | + return failed |
39 | 62 |
|
40 | 63 |
|
41 | 64 | def run_test_suite_with_junit_output(): |
@@ -87,7 +110,9 @@ def finalize_options(self): |
87 | 110 | pass |
88 | 111 |
|
89 | 112 | def run(self): |
90 | | - run_test_suite() |
| 113 | + failed = run_test_suite() |
| 114 | + if failed: |
| 115 | + sys.exit(1) |
91 | 116 |
|
92 | 117 |
|
93 | 118 | class JunitXmlTestCommand(Command): |
@@ -170,15 +195,17 @@ def run(self): |
170 | 195 | spl.close() |
171 | 196 |
|
172 | 197 | # Create searchcommands_app-<three-part-version-number>-private.tar.gz |
| 198 | + # but only if we are on 2.7 or later |
| 199 | + if sys.version_info >= (2,7): |
| 200 | + setup_py = os.path.join('examples', 'searchcommands_app', 'setup.py') |
173 | 201 |
|
174 | | - setup_py = os.path.join('examples', 'searchcommands_app', 'setup.py') |
175 | | - |
176 | | - check_call(('python', setup_py, 'build', '--force'), stderr=STDOUT, stdout=sys.stdout) |
177 | | - tarball = 'searchcommands_app-{0}-private.tar.gz'.format(self.distribution.metadata.version) |
178 | | - source = os.path.join('examples', 'searchcommands_app', 'build', tarball) |
179 | | - target = os.path.join('build', tarball) |
| 202 | + check_call(('python', setup_py, 'build', '--force'), stderr=STDOUT, stdout=sys.stdout) |
| 203 | + tarball = 'searchcommands_app-{0}-private.tar.gz'.format(self.distribution.metadata.version) |
| 204 | + source = os.path.join('examples', 'searchcommands_app', 'build', tarball) |
| 205 | + target = os.path.join('build', tarball) |
180 | 206 |
|
181 | | - shutil.copyfile(source, target) |
| 207 | + shutil.copyfile(source, target) |
| 208 | + |
182 | 209 | return |
183 | 210 |
|
184 | 211 | setup( |
|
0 commit comments