Skip to content

Commit

Permalink
Testcase reports with a url attribute will now properly write this to…
Browse files Browse the repository at this point in the history
… junitxml
  • Loading branch information
John Towler committed Aug 25, 2016
1 parent 9c45d6c commit 1b259f7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions _pytest/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def record_testreport(self, testreport):
}
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):
Expand Down
25 changes: 25 additions & 0 deletions testing/test_junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,3 +922,28 @@ class Report(BaseReport):
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"

0 comments on commit 1b259f7

Please sign in to comment.