|
1 | 1 |
|
| 2 | +import argparse |
2 | 3 | import sys |
3 | 4 | import time |
4 | 5 |
|
@@ -126,21 +127,33 @@ def _initArgParsers(self): |
126 | 127 | super(XMLTestProgram, self)._initArgParsers() |
127 | 128 |
|
128 | 129 | for parser in (self._main_parser, self._discovery_parser): |
129 | | - parser.add_argument('-o', '--output', metavar='DIR', |
| 130 | + group = parser.add_mutually_exclusive_group() |
| 131 | + group.add_argument('-o', '--output', metavar='DIR', |
130 | 132 | help='Directory for storing XML reports ' |
131 | 133 | "('.' default)") |
| 134 | + group.add_argument('--output-file', metavar='FILENAME', |
| 135 | + help='Filename for storing XML report') |
132 | 136 |
|
133 | 137 | def runTests(self): |
134 | | - if self.output is not None: |
135 | | - kwargs = dict(verbosity=self.verbosity, |
136 | | - failfast=self.failfast, |
137 | | - buffer=self.buffer, |
138 | | - warnings=self.warnings, |
139 | | - output=self.output) |
| 138 | + kwargs = dict( |
| 139 | + verbosity=self.verbosity, |
| 140 | + failfast=self.failfast, |
| 141 | + buffer=self.buffer, |
| 142 | + warnings=self.warnings, |
| 143 | + ) |
| 144 | + if sys.version_info[:2] > (3, 4): |
| 145 | + kwargs.update(tb_locals=self.tb_locals) |
140 | 146 |
|
141 | | - if sys.version_info[:2] > (3, 4): |
142 | | - kwargs.update(tb_locals=self.tb_locals) |
| 147 | + output_file = None |
| 148 | + try: |
| 149 | + if self.output_file is not None: |
| 150 | + output_file = open(self.output_file, 'wb') |
| 151 | + kwargs.update(output=output_file) |
| 152 | + elif self.output is not None: |
| 153 | + kwargs.update(output=self.output) |
143 | 154 |
|
144 | 155 | self.testRunner = self.testRunner(**kwargs) |
145 | | - |
146 | | - super(XMLTestProgram, self).runTests() |
| 156 | + super(XMLTestProgram, self).runTests() |
| 157 | + finally: |
| 158 | + if output_file is not None: |
| 159 | + output_file.close() |
0 commit comments