Skip to content

Commit 2419df8

Browse files
author
Ubuntu
committed
Enable record_property for junit_family=xunit2
1 parent 75609e7 commit 2419df8

3 files changed

Lines changed: 44 additions & 10 deletions

File tree

changelog/14315.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Enabled ``record_property`` when using ``junit_family=xunit2``.

src/_pytest/junitxml.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ def record_property(request: FixtureRequest) -> Callable[[str, object], None]:
288288
def test_function(record_property):
289289
record_property("example_key", 1)
290290
"""
291-
_warn_incompatibility_with_xunit2(request, "record_property")
292291

293292
def append_property(name: str, value: object) -> None:
294293
request.node.user_properties.append((name, value))

testing/test_junitxml.py

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,12 +1378,46 @@ def test_record(record_xml_attribute, other):
13781378
)
13791379

13801380

1381+
@pytest.mark.filterwarnings("default")
1382+
def test_record_property_xunit2(pytester: Pytester, run_and_parse: RunAndParse) -> None:
1383+
pytester.makeini(
1384+
"""
1385+
[pytest]
1386+
junit_family = xunit2
1387+
"""
1388+
)
1389+
pytester.makepyfile(
1390+
"""
1391+
import pytest
1392+
1393+
@pytest.fixture
1394+
def other(record_property):
1395+
record_property("bar", 1)
1396+
1397+
def test_record(record_property, other):
1398+
record_property("foo", "<1")
1399+
"""
1400+
)
1401+
1402+
result, dom = run_and_parse(family=None)
1403+
node = dom.get_first_by_tag("testsuite")
1404+
tnode = node.get_first_by_tag("testcase")
1405+
psnode = tnode.get_first_by_tag("properties")
1406+
pnodes = psnode.find_by_tag("property")
1407+
pnodes[0].assert_attr(name="bar", value="1")
1408+
pnodes[1].assert_attr(name="foo", value="<1")
1409+
1410+
result.stdout.no_fnmatch_line(
1411+
"*record_property is incompatible with junit_family 'xunit2'*"
1412+
)
1413+
1414+
13811415
@pytest.mark.filterwarnings("default")
13821416
@pytest.mark.parametrize("fixture_name", ["record_xml_attribute", "record_property"])
13831417
def test_record_fixtures_xunit2(
13841418
pytester: Pytester, fixture_name: str, run_and_parse: RunAndParse
13851419
) -> None:
1386-
"""Ensure record_xml_attribute and record_property drop values when outside of legacy family."""
1420+
"""Ensure xunit2 still warns for record_xml_attribute, but record_property remains supported."""
13871421
pytester.makeini(
13881422
"""
13891423
[pytest]
@@ -1403,16 +1437,16 @@ def test_record({fixture_name}, other):
14031437
)
14041438

14051439
result, _dom = run_and_parse(family=None)
1406-
expected_lines = []
14071440
if fixture_name == "record_xml_attribute":
1408-
expected_lines.append(
1409-
"*test_record_fixtures_xunit2.py:6:*record_xml_attribute is an experimental feature"
1441+
expected_lines = [
1442+
"*test_record_fixtures_xunit2.py:6:*record_xml_attribute is incompatible "
1443+
"with junit_family 'xunit2' (use 'legacy' or 'xunit1')"
1444+
]
1445+
result.stdout.fnmatch_lines(expected_lines)
1446+
else:
1447+
result.stdout.no_fnmatch_line(
1448+
"*record_property is incompatible with junit_family 'xunit2'*"
14101449
)
1411-
expected_lines = [
1412-
f"*test_record_fixtures_xunit2.py:6:*{fixture_name} is incompatible "
1413-
"with junit_family 'xunit2' (use 'legacy' or 'xunit1')"
1414-
]
1415-
result.stdout.fnmatch_lines(expected_lines)
14161450

14171451

14181452
def test_random_report_log_xdist(

0 commit comments

Comments
 (0)