Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show skip reason in junitxml "message" field #441

Merged
merged 1 commit into from
Apr 2, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ nose2 uses semantic versioning (currently in 0.x) and the popular
Unreleased
----------

Changed
~~~~~~~

* skipped tests now include the user's reason in junit XML's "message" field

Fixed
~~~~~

Expand Down
5 changes: 4 additions & 1 deletion nose2/plugins/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ def testOutcome(self, event):
self.skipped += 1
skipped = ET.SubElement(testcase, 'skipped')
if msg:
skipped.set('message', 'test skipped')
skipmsg = 'test skipped'
if event.reason:
skipmsg = 'test skipped: {}'.format(event.reason)
skipped.set('message', skipmsg)
skipped.text = msg
elif event.outcome == result.FAIL and event.expected:
self.skipped += 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import unittest


class Test(unittest.TestCase):

@unittest.skip('ohai')
def test(self):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[unittest]
plugins = nose2.plugins.junitxml

[junit-xml]
always-on = True
25 changes: 24 additions & 1 deletion nose2/tests/functional/test_junitxml_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def test_report_location_should_be_resilent_to_chdir_in_tests(self):
"Searched for " + junit_report)

def test_report_includes_properties(self):
scenario = ('scenario', 'junitxml', 'with_properties')
work_dir = os.getcwd()
with open(os.path.join(work_dir, 'properties.json'), 'w') as fh:
fh.write('{"PROPERTY_NAME":"PROPERTY_VALUE"}')
Expand All @@ -107,6 +106,30 @@ def test_report_includes_properties(self):
self.assertEqual(prop.get('name'), 'PROPERTY_NAME')
self.assertEqual(prop.get('value'), 'PROPERTY_VALUE')

def test_skip_reason_in_message(self):
junit_report, proc = self.run_with_junitxml_loaded(
("scenario", "junitxml", "skip_reason"), "--junit-xml")

self.assertTestRunOutputMatches(
proc,
stderr=r"test \(test_junitxml_skip_reason.Test\) \.* skip")

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

with open(junit_report, "r") as fh:
tree = ET.parse(fh).getroot()

num_test_cases = len(tree.findall('testcase'))
assert num_test_cases == 1

num_skipped = len(tree.find('testcase').findall("skipped"))
assert num_skipped == 1
skip_node = tree.find('testcase').find("skipped")
assert "message" in skip_node.attrib
skip_message = skip_node.get("message")
assert skip_message == "test skipped: ohai"


class JunitXmlPluginFunctionalFailureTest(FunctionalTestCase, TestCase):
def test_failure_to_write_report(self):
Expand Down
2 changes: 1 addition & 1 deletion nose2/tests/unit/test_junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_skip_includes_skipped(self):
case = self.plugin.tree.find('testcase')
skip = case.find('skipped')
assert skip is not None
self.assertEqual(skip.get('message'), 'test skipped')
self.assertEqual(skip.get('message'), 'test skipped: skip')
self.assertEqual(skip.text, 'skip')

def test_skip_includes_skipped_no_reason(self):
Expand Down