Skip to content

Commit

Permalink
Merge 7b2e31e into fd5af12
Browse files Browse the repository at this point in the history
  • Loading branch information
eamars committed Jul 9, 2019
2 parents fd5af12 + 7b2e31e commit 1995412
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
15 changes: 15 additions & 0 deletions nose2/plugins/junitxml.py
Expand Up @@ -93,6 +93,7 @@ class JUnitXmlReporter(events.Plugin):
commandLineSwitch = ('X', 'junit-xml', 'Generate junit-xml output report')

def __init__(self):
# Read argument from configuration file, or filled with default
self.path = os.path.realpath(
self.config.as_str('path', default='nose2-junit.xml'))
self.keep_restricted = self.config.as_bool(
Expand All @@ -101,6 +102,7 @@ def __init__(self):
'test_properties', default=None)
self.test_fullname = self.config.as_bool(
'test_fullname', default=False)

if self.test_properties is not None:
self.test_properties_path = os.path.realpath(self.test_properties)
self.errors = 0
Expand All @@ -110,6 +112,19 @@ def __init__(self):
self.tree = ET.Element('testsuite')
self._start = None

# Allow user to override certain option from command line
group = self.session.pluginargs
group.add_argument(
'--junit-xml-path', action='store', default='', metavar='FILE',
dest='path', help='Output XML filename'
)

def handleArgs(self, event):
"""Read option from command line and override the value in config file
when necessary"""
if event.args.path:
self.path = os.path.realpath(event.args.path)

def startTest(self, event):
"""Count test, record start time"""
self.numtests += 1
Expand Down
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-

import unittest


class Test(unittest.TestCase):

def test(self):
pass
@@ -0,0 +1,2 @@
[junit-xml]
path = a.xml
37 changes: 35 additions & 2 deletions nose2/tests/functional/test_junitxml_plugin.py
Expand Up @@ -10,10 +10,10 @@
class JunitXmlPluginFunctionalTest(FunctionalTestCase, TestCase):
_RUN_IN_TEMP = True

def run_with_junitxml_loaded(self, scenario, *args):
def run_with_junitxml_loaded(self, scenario, *args, **kwargs):
work_dir = os.getcwd()
test_dir = support_file(*scenario)
junit_report = os.path.join(work_dir, 'nose2-junit.xml')
junit_report = os.path.join(work_dir, kwargs.get('junit_report', 'nose2-junit.xml'))
config = os.path.join(test_dir, 'unittest.cfg')
config_args = ()
if os.path.exists(junit_report):
Expand Down Expand Up @@ -130,6 +130,39 @@ def test_skip_reason_in_message(self):
skip_message = skip_node.get("message")
assert skip_message == "test skipped: ohai"

def test_xml_path_override_by_config(self):
junit_report, proc = self.run_with_junitxml_loaded(
("scenario", "junitxml", "non_default_path"),
"--junit-xml",
junit_report="a.xml"
)

self.assertTestRunOutputMatches(
proc,
stderr='test \(test_junitxml_non_default_path.Test\) \.* ok')

exit_status = proc.poll()
assert exit_status == 0

self.assertTrue(os.path.isfile(junit_report))

def test_xml_path_override_by_command(self):
junit_report, proc = self.run_with_junitxml_loaded(
("scenario", "junitxml", "non_default_path"),
"--junit-xml",
"--junit-xml-path=b.xml",
junit_report="b.xml"
)

self.assertTestRunOutputMatches(
proc,
stderr='test \(test_junitxml_non_default_path.Test\) \.* ok')

exit_status = proc.poll()
assert exit_status == 0

self.assertTrue(os.path.isfile(junit_report))


class JunitXmlPluginFunctionalFailureTest(FunctionalTestCase, TestCase):
def test_failure_to_write_report(self):
Expand Down

0 comments on commit 1995412

Please sign in to comment.