Improve docs and using warning system for record_xml_property fixture
This commit is contained in:
parent
a20c6d072d
commit
70da93145d
|
@ -138,8 +138,8 @@
|
||||||
- fix issue890: changed extension of all documentation files from ``txt`` to
|
- fix issue890: changed extension of all documentation files from ``txt`` to
|
||||||
``rst``. Thanks to Abhijeet for the PR.
|
``rst``. Thanks to Abhijeet for the PR.
|
||||||
|
|
||||||
- implement feature on issue951: support to log additional information on xml
|
- issue951: add new record_xml_property fixture, that supports logging
|
||||||
output.
|
additional information on xml output. Thanks David Diaz for the PR.
|
||||||
|
|
||||||
2.7.3 (compared to 2.7.2)
|
2.7.3 (compared to 2.7.2)
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
|
@ -56,11 +56,17 @@ def bin_xml_escape(arg):
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def record_xml_property(request):
|
def record_xml_property(request):
|
||||||
if hasattr(request.config, "_xml"):
|
"""Fixture that adds extra xml properties to the tag for the calling test.
|
||||||
return request.config._xml.record_property
|
The fixture is callable with (name, value), with value being automatically
|
||||||
def dummy(*args, **kwargs):
|
xml-encoded.
|
||||||
pass
|
"""
|
||||||
return dummy
|
def inner(name, value):
|
||||||
|
if hasattr(request.config, "_xml"):
|
||||||
|
request.config._xml.add_custom_property(name, value)
|
||||||
|
msg = 'record_xml_property is an experimental feature'
|
||||||
|
request.config.warn(code='C3', message=msg,
|
||||||
|
fslocation=request.node.location[:2])
|
||||||
|
return inner
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
group = parser.getgroup("terminal reporting")
|
group = parser.getgroup("terminal reporting")
|
||||||
|
@ -99,7 +105,7 @@ class LogXML(object):
|
||||||
self.failed = self.errors = 0
|
self.failed = self.errors = 0
|
||||||
self.custom_properties = {}
|
self.custom_properties = {}
|
||||||
|
|
||||||
def record_property(self, name, value):
|
def add_custom_property(self, name, value):
|
||||||
self.custom_properties[str(name)] = bin_xml_escape(str(value))
|
self.custom_properties[str(name)] = bin_xml_escape(str(value))
|
||||||
|
|
||||||
def _opentestcase(self, report):
|
def _opentestcase(self, report):
|
||||||
|
|
|
@ -153,18 +153,35 @@ integration servers, use this invocation::
|
||||||
|
|
||||||
to create an XML file at ``path``.
|
to create an XML file at ``path``.
|
||||||
|
|
||||||
If you want to log additional information for a test, you can use
|
record_xml_property
|
||||||
record_property("key", value)::
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
import pytest
|
.. versionadded:: 2.8
|
||||||
def test_function():
|
|
||||||
...
|
|
||||||
pytest.record_property("example_key", 1)
|
|
||||||
...
|
|
||||||
|
|
||||||
Warning:
|
If you want to log additional information for a test, you can use the
|
||||||
- This is a preliminary feature.
|
``record_xml_property`` fixture:
|
||||||
- Using this feature will break any schema verification.
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
def test_function(record_xml_property):
|
||||||
|
record_xml_property("example_key", 1)
|
||||||
|
assert 0
|
||||||
|
|
||||||
|
This will add an extra property ``example_key="1"`` to the generated
|
||||||
|
``testcase`` tag:
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<testcase classname="test_function" example_key="1" file="test_function.py" line="0" name="test_function" time="0.0009">
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
|
||||||
|
This is an experimental feature, and its interface might be replaced
|
||||||
|
by something more powerful and general in future versions. The
|
||||||
|
functionality per-se will be kept, however.
|
||||||
|
|
||||||
|
Also please note that using this feature will break any schema verification.
|
||||||
|
This might be a problem when used with some CI servers.
|
||||||
|
|
||||||
Creating resultlog format files
|
Creating resultlog format files
|
||||||
----------------------------------------------------
|
----------------------------------------------------
|
||||||
|
|
|
@ -557,7 +557,8 @@ def test_record_property(testdir):
|
||||||
def test_record(record_xml_property):
|
def test_record(record_xml_property):
|
||||||
record_xml_property("foo", "<1");
|
record_xml_property("foo", "<1");
|
||||||
""")
|
""")
|
||||||
result, dom = runandparse(testdir)
|
result, dom = runandparse(testdir, '-rw')
|
||||||
node = dom.getElementsByTagName("testsuite")[0]
|
node = dom.getElementsByTagName("testsuite")[0]
|
||||||
tnode = node.getElementsByTagName("testcase")[0]
|
tnode = node.getElementsByTagName("testcase")[0]
|
||||||
assert_attr(tnode, foo="<1")
|
assert_attr(tnode, foo="<1")
|
||||||
|
result.stdout.fnmatch_lines('*C3*test_record_property.py*experimental*')
|
||||||
|
|
Loading…
Reference in New Issue