Correcting implementation based on pull request feed back

This commit is contained in:
David Diaz 2015-08-21 14:31:20 -06:00
parent 24212fd97f
commit 2ddbac1f98
5 changed files with 16 additions and 15 deletions

View File

@ -60,3 +60,4 @@ Samuele Pedroni
Tom Viner
Trevor Bekolay
Wouter van Ackooy
David Díaz-Barquero

View File

@ -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)
-----------------------------

View File

@ -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("/", '.')

View File

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

View File

@ -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]