Skip to content

Commit 317396b

Browse files
committed
Add --output-file option
1 parent b7bfcc4 commit 317396b

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

xmlrunner/runner.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
import argparse
23
import sys
34
import time
45

@@ -126,21 +127,33 @@ def _initArgParsers(self):
126127
super(XMLTestProgram, self)._initArgParsers()
127128

128129
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',
130132
help='Directory for storing XML reports '
131133
"('.' default)")
134+
group.add_argument('--output-file', metavar='FILENAME',
135+
help='Filename for storing XML report')
132136

133137
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)
140146

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)
143154

144155
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

Comments
 (0)