From 1b259f70f3e0eac4eb0af441b7a18779b2c4ac58 Mon Sep 17 00:00:00 2001 From: John Towler Date: Thu, 25 Aug 2016 13:08:51 -0700 Subject: [PATCH] Testcase reports with a url attribute will now properly write this to junitxml --- CHANGELOG.rst | 5 ++++- _pytest/junitxml.py | 2 ++ testing/test_junitxml.py | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 447b03b94..8abe4c48c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,9 +9,12 @@ * Add ``buffer`` attribute to stdin stub class ``pytest.capture.DontReadFromInput`` Thanks `@joguSD`_ for the PR. -* +* Testcase reports with a url attribute will now properly write this to junitxml. + Thanks `@fushi`_ for the PR + .. _@joguSD: https://github.com/joguSD +.. _@fushi: https://github.com/fushi .. _#1857: https://github.com/pytest-dev/pytest/issues/1857 diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index da190ff21..88e4f5282 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -102,6 +102,8 @@ class _NodeReporter(object): } if testreport.location[1] is not None: attrs["line"] = testreport.location[1] + if hasattr(testreport, "url"): + attrs["url"] = testreport.url self.attrs = attrs def to_xml(self): diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index aec2741f1..382d7c137 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -922,3 +922,28 @@ def test_global_properties(testdir): actual[k] = v assert actual == expected + + +def test_url_property(testdir): + test_url = "http://www.github.com/pytest-dev" + path = testdir.tmpdir.join("test_url_property.xml") + log = LogXML(str(path), None) + from _pytest.runner import BaseReport + + class Report(BaseReport): + longrepr = "FooBarBaz" + sections = [] + nodeid = "something" + location = 'tests/filename.py', 42, 'TestClass.method' + url = test_url + + test_report = Report() + + log.pytest_sessionstart() + node_reporter = log._opentestcase(test_report) + node_reporter.append_failure(test_report) + log.pytest_sessionfinish() + + test_case = minidom.parse(str(path)).getElementsByTagName('testcase')[0] + + assert (test_case.getAttribute('url') == test_url), "The URL did not get written to the xml" \ No newline at end of file