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

Testcase reports with a url attribute will now properly write this to… #1874

Merged
merged 1 commit into from
Sep 19, 2016
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"