diff --git a/AUTHORS b/AUTHORS index 2fdc39fc2..5d9a162eb 100644 --- a/AUTHORS +++ b/AUTHORS @@ -60,3 +60,4 @@ Samuele Pedroni Tom Viner Trevor Bekolay Wouter van Ackooy +David Díaz-Barquero diff --git a/CHANGELOG b/CHANGELOG index 7d96418c8..b66eeb95f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -138,6 +138,9 @@ - fix issue890: changed extension of all documentation files from ``txt`` to ``rst``. Thanks to Abhijeet for the PR. +- implement feature on issue951: support to log additional information on xml + output. + 2.7.3 (compared to 2.7.2) ----------------------------- diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index 0c79d2951..c481fc1f0 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -9,6 +9,7 @@ import os import re import sys import time +import pytest # Python 2.X and 3.X compatibility if sys.version_info[0] < 3: @@ -53,12 +54,13 @@ def bin_xml_escape(arg): return unicode('#x%04X') % i return py.xml.raw(illegal_xml_re.sub(repl, py.xml.escape(arg))) -def record_property(name, value): - if hasattr(record_property, 'binding'): - record_property.binding(name, value) - -def pytest_namespace(): - return dict(record_property=record_property) +@pytest.fixture +def record_xml_property(request): + if hasattr(request.config, "_xml"): + return request.config._xml.record_property + def dummy(*args, **kwargs): + pass + return dummy def pytest_addoption(parser): group = parser.getgroup("terminal reporting") @@ -76,18 +78,12 @@ def pytest_configure(config): config._xml = LogXML(xmlpath, config.option.junitprefix) config.pluginmanager.register(config._xml) - def binding(name, value): - config._xml.record_property(name, value) - record_property.binding = binding - def pytest_unconfigure(config): xml = getattr(config, '_xml', None) if xml: del config._xml config.pluginmanager.unregister(xml) - del record_property.binding - def mangle_testnames(names): names = [x.replace(".py", "") for x in names if x != '()'] names[0] = names[0].replace("/", '.') diff --git a/doc/en/usage.rst b/doc/en/usage.rst index baa625bdb..6c79d5eb0 100644 --- a/doc/en/usage.rst +++ b/doc/en/usage.rst @@ -162,6 +162,8 @@ record_property("key", value):: pytest.record_property("example_key", 1) ... +Warning: using this feature will break any schema verification. + Creating resultlog format files ---------------------------------------------------- diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 2ff9ca6ed..706b4e639 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -554,9 +554,8 @@ def test_unicode_issue368(testdir): def test_record_property(testdir): testdir.makepyfile(""" - from pytest import record_property - def test_record(): - record_property("foo", "<1"); + def test_record(record_xml_property): + record_xml_property("foo", "<1"); """) result, dom = runandparse(testdir) node = dom.getElementsByTagName("testsuite")[0]