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
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"