Skip to content

Commit 1b259f7

Browse files
author
John Towler
committed
Testcase reports with a url attribute will now properly write this to junitxml
1 parent 9c45d6c commit 1b259f7

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
* Add ``buffer`` attribute to stdin stub class ``pytest.capture.DontReadFromInput``
1010
Thanks `@joguSD`_ for the PR.
1111

12-
*
12+
* Testcase reports with a url attribute will now properly write this to junitxml.
13+
Thanks `@fushi`_ for the PR
14+
1315

1416
.. _@joguSD: https://github.com/joguSD
17+
.. _@fushi: https://github.com/fushi
1518

1619
.. _#1857: https://github.com/pytest-dev/pytest/issues/1857
1720

_pytest/junitxml.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ def record_testreport(self, testreport):
102102
}
103103
if testreport.location[1] is not None:
104104
attrs["line"] = testreport.location[1]
105+
if hasattr(testreport, "url"):
106+
attrs["url"] = testreport.url
105107
self.attrs = attrs
106108

107109
def to_xml(self):

testing/test_junitxml.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,3 +922,28 @@ class Report(BaseReport):
922922
actual[k] = v
923923

924924
assert actual == expected
925+
926+
927+
def test_url_property(testdir):
928+
test_url = "http://www.github.com/pytest-dev"
929+
path = testdir.tmpdir.join("test_url_property.xml")
930+
log = LogXML(str(path), None)
931+
from _pytest.runner import BaseReport
932+
933+
class Report(BaseReport):
934+
longrepr = "FooBarBaz"
935+
sections = []
936+
nodeid = "something"
937+
location = 'tests/filename.py', 42, 'TestClass.method'
938+
url = test_url
939+
940+
test_report = Report()
941+
942+
log.pytest_sessionstart()
943+
node_reporter = log._opentestcase(test_report)
944+
node_reporter.append_failure(test_report)
945+
log.pytest_sessionfinish()
946+
947+
test_case = minidom.parse(str(path)).getElementsByTagName('testcase')[0]
948+
949+
assert (test_case.getAttribute('url') == test_url), "The URL did not get written to the xml"

0 commit comments

Comments
 (0)