Skip to content

Commit 2e57d1e

Browse files
committed
Tweak junit-xml test config
1 parent ade8567 commit 2e57d1e

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

hypothesis-python/RELEASE.rst

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
RELEASE_TYPE: patch
22

3-
The Hypothesis pytest plugin was not outputting valid xunit2 nodes when ``--junit-xml`` was specified. This has been broken since Pytest 5.4, which changed the internal API for adding nodes to the junit report.
3+
The Hypothesis pytest plugin was not outputting valid xunit2 nodes when
4+
``--junit-xml`` was specified. This has been broken since Pytest 5.4, which
5+
changed the internal API for adding nodes to the junit report.
46

5-
This also fixes the issue when using hypothesis with ``--junit-xml`` and ``pytest-xdist`` where the junit xml report would not be xunit2 compatible. Now, when using with ``pytest-xdist``, the junit report will just omit the ``<properties>`` node.
7+
This also fixes the issue when using hypothesis with ``--junit-xml`` and
8+
``pytest-xdist`` where the junit xml report would not be xunit2 compatible.
9+
Now, when using with ``pytest-xdist``, the junit report will just omit the
10+
``<properties>`` node.
611

7-
References:
8-
* https://github.com/pytest-dev/pytest/issues/7767#issuecomment-1082436256
9-
* https://github.com/pytest-dev/pytest/issues/1126#issuecomment-484581283
10-
* :issue:`1935`
12+
For more details, see `this pytest issue <https://github.com/pytest-dev/pytest/issues/1126#issuecomment-484581283>`__,
13+
`this pytest issue <https://github.com/pytest-dev/pytest/issues/7767#issuecomment-1082436256>`__,
14+
and :issue:`1935`
1115

1216
Thanks to Brandon Chinn for this bug fix!

hypothesis-python/tests/pytest/test_junit.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,37 @@ def _run_and_get_junit(testdir, *args):
3737
def _findall_from_root(junit_xml, path):
3838
if junit_xml.tag == "testsuites":
3939
return junit_xml.findall(f"./testsuite/{path}")
40-
else:
41-
# < pytest 5.1.0
42-
# https://github.com/pytest-dev/pytest/commit/a43ba78d3bde1630a42aaa95776687d3886891e6
43-
return junit_xml.findall(f"./{path}")
40+
# This case only exists for tests against Pytest before 5.1.0;
41+
# see https://github.com/pytest-dev/pytest/commit/a43ba78d3bde
42+
return junit_xml.findall(f"./{path}")
4443

4544

46-
def test_outputs_valid_xunit2(testdir):
47-
junit_xml = _run_and_get_junit(testdir)
48-
45+
def suite_properties_ok(junit_xml):
46+
# Check whether <properties> is included in <testsuite>. This is currently not
47+
# the case when using pytest-xdist, which is a shame, but we can live with it.
4948
testsuite_props = _findall_from_root(junit_xml, "properties")
50-
assert len(testsuite_props) == 1
51-
assert {prop.get("name") for prop in testsuite_props[0].findall("property")} == {
49+
return len(testsuite_props) == 1 and {
50+
prop.get("name") for prop in testsuite_props[0].findall("property")
51+
} == {
5252
"hypothesis-statistics-test_outputs_valid_xunit2.py::test_valid",
5353
"hypothesis-statistics-test_outputs_valid_xunit2.py::test_invalid",
5454
}
5555

56+
57+
def test_outputs_valid_xunit2(testdir):
58+
# The thing we really care about with pytest-xdist + junitxml is that we don't
59+
# break xunit2 compatibility by putting <properties> inside <testcase>.
60+
junit_xml = _run_and_get_junit(testdir)
5661
testcase_props = _findall_from_root(junit_xml, "testcase/properties")
5762
assert len(testcase_props) == 0
63+
# Check whether <properties> is included in <testsuite>
64+
assert suite_properties_ok(junit_xml)
5865

5966

6067
def test_outputs_valid_xunit2_with_xdist(testdir):
6168
junit_xml = _run_and_get_junit(testdir, "-n2")
62-
6369
testcase_props = _findall_from_root(junit_xml, "testcase/properties")
6470
assert len(testcase_props) == 0
71+
# If <properties> is included in <testsuite>, this assertion will fail.
72+
# That would be a GOOD THING, and we would remove the `not` to prevent regressions.
73+
assert not suite_properties_ok(junit_xml)

0 commit comments

Comments
 (0)