Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,27 @@ def test_xmlrunner_output_file(self, exiter, testrunner, opener):
testrunner.assert_called_once_with(**kwargs)
exiter.assert_called_once_with(False)

@mock.patch('sys.argv', ['xmlrunner', '--outsuffix', ''])
@mock.patch('xmlrunner.runner.open')
@mock.patch('xmlrunner.runner.XMLTestRunner')
@mock.patch('sys.exit')
def test_xmlrunner_outsuffix(self, exiter, testrunner, opener):
xmlrunner.runner.XMLTestProgram()

kwargs = dict(
buffer=mock.ANY,
failfast=mock.ANY,
verbosity=mock.ANY,
warnings=mock.ANY,
outsuffix='',
)

if sys.version_info[:2] > (3, 4):
kwargs.update(tb_locals=mock.ANY)

testrunner.assert_called_once_with(**kwargs)
exiter.assert_called_once_with(False)


class ResolveFilenameTestCase(unittest.TestCase):
@mock.patch('os.path.relpath')
Expand Down
13 changes: 12 additions & 1 deletion xmlrunner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class XMLTestRunner(TextTestRunner):
"""
A test runner class that outputs the results in JUnit like XML files.
"""
def __init__(self, output='.', outsuffix=None,

def __init__(self, output='.', outsuffix=None,
elapsed_times=True, encoding=UTF8,
resultclass=None,
**kwargs):
Expand Down Expand Up @@ -138,9 +139,13 @@ def _parseKnownArgs(self, kwargs):
group.add_argument(
'--output-file', metavar='FILENAME',
help='Filename for storing XML report')
parser.add_argument(
'--outsuffix', metavar='STRING',
help='Output suffix (timestamp is default)')
namespace, argv = parser.parse_known_args(argv)
self.output = namespace.output
self.output_file = namespace.output_file
self.outsuffix = namespace.outsuffix
kwargs['argv'] = argv

def _initArgParsers(self):
Expand All @@ -155,6 +160,9 @@ def _initArgParsers(self):
group.add_argument(
'--output-file', metavar='FILENAME', nargs=1,
help='Filename for storing XML report')
group.add_argument(
'--outsuffix', metavar='STRING', nargs=1,
help='Output suffix (timestamp is default)')

def runTests(self):
kwargs = dict(
Expand All @@ -174,6 +182,9 @@ def runTests(self):
elif self.output is not None:
kwargs.update(output=self.output)

if self.outsuffix is not None:
kwargs.update(outsuffix=self.outsuffix)

self.testRunner = self.testRunner(**kwargs)
super(XMLTestProgram, self).runTests()
finally:
Expand Down