summaryrefslogtreecommitdiff
path: root/doc/en/usage.rst
diff options
context:
space:
mode:
authorCarlos Jenkins <carlos@jenkins.co.cr>2017-08-16 05:23:28 -0600
committerCarlos Jenkins <carlos.jenkins@hpe.com>2018-02-20 15:46:26 -0600
commit8b49ddfa585e8dee77ba3aeef654598e0052237e (patch)
treed318b90f4484f500f5c7b73456e178cf07dd19c3 /doc/en/usage.rst
parent97bb6abcfa4d78f5bd9d0478d4aecd32d4910974 (diff)
downloadpytest-8b49ddfa585e8dee77ba3aeef654598e0052237e.tar.gz
Renamed the fixture record_xml_property to record_property and adapted logic so that the properties are passed to the TestReport object and thus allow compatibility with pytest-xdist.
Diffstat (limited to 'doc/en/usage.rst')
-rw-r--r--doc/en/usage.rst54
1 files changed, 44 insertions, 10 deletions
diff --git a/doc/en/usage.rst b/doc/en/usage.rst
index abd8bac2b..2b86420bb 100644
--- a/doc/en/usage.rst
+++ b/doc/en/usage.rst
@@ -220,19 +220,24 @@ To set the name of the root test suite xml item, you can configure the ``junit_s
[pytest]
junit_suite_name = my_suite
-record_xml_property
+record_property
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. versionadded:: 2.8
+.. versionchanged:: 3.5
+
+ Fixture renamed from ``record_xml_property`` to ``record_property`` as user
+ properties are now available to all reporters.
+ ``record_xml_property`` is now deprecated.
If you want to log additional information for a test, you can use the
-``record_xml_property`` fixture:
+``record_property`` fixture:
.. code-block:: python
- def test_function(record_xml_property):
- record_xml_property("example_key", 1)
- assert 0
+ def test_function(record_property):
+ record_property("example_key", 1)
+ assert True
This will add an extra property ``example_key="1"`` to the generated
``testcase`` tag:
@@ -245,13 +250,42 @@ This will add an extra property ``example_key="1"`` to the generated
</properties>
</testcase>
-.. warning::
+Alternatively, you can integrate this functionality with custom markers:
- ``record_xml_property`` 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.
+.. code-block:: python
+
+ # content of conftest.py
+
+ def pytest_collection_modifyitems(session, config, items):
+ for item in items:
+ marker = item.get_marker('test_id')
+ if marker is not None:
+ test_id = marker.args[0]
+ item.user_properties.append(('test_id', test_id))
+
+And in your tests:
+
+.. code-block:: python
+
+ # content of test_function.py
+
+ @pytest.mark.test_id(1501)
+ def test_function():
+ assert True
+
+Will result in:
+
+.. code-block:: xml
+
+ <testcase classname="test_function" file="test_function.py" line="0" name="test_function" time="0.0009">
+ <properties>
+ <property name="test_id" value="1501" />
+ </properties>
+ </testcase>
+
+.. warning::
- Currently it does not work when used with the ``pytest-xdist`` plugin.
+ ``record_property`` is an experimental feature and may change in the future.
Also please note that using this feature will break any schema verification.
This might be a problem when used with some CI servers.