Skip to content

Commit ff8ae30

Browse files
committed
gh-155485: Skip test_subparser_inherits_reparse_deferral with Expat < 2.6.0
The test was added in 7d76013, and fails when CPython is compiled against expat < 2.6.0: test_subparser_inherits_reparse_deferral (test.test_pyexpat.ParentParserLifetimeTest.test_subparser_inherits_reparse_deferral) ... FAIL ====================================================================== FAIL: test_subparser_inherits_reparse_deferral (test.test_pyexpat.ParentParserLifetimeTest.test_subparser_inherits_reparse_deferral) ---------------------------------------------------------------------- Traceback (most recent call last): File "/builddir/build/BUILD/Python-3.13.15/Lib/test/test_pyexpat.py", line 960, in test_subparser_inherits_reparse_deferral self.assertEqual(subparser.GetReparseDeferralEnabled(), enabled) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError: False != True ---------------------------------------------------------------------- With XML_COMBINED_VERSION < 20600, SetReparseDeferralEnabled is a complete no-op[1], both the expat call and the cache update are inside #if XML_COMBINED_VERSION >= 20600. The cache stays at its initial value of false[2], which the subparser copies and GetReparseDeferralEnabled returns. The test's enabled=True iteration then asserts False == True. This is consistent with the documented behavior[3]: GetReparseDeferralEnabled says "always returns false with Expat <2.6.0". Hence, the test makes no sense on Expat < 2.6.0. Similarly to gh-144739, the test's skip decorator needs to check for the compile-time Expat version, as the behavior is determined by #ifs, not by runtime capabilities. Python compiled with Expat 2.5.x still fails the test even if Expat was updated to 2.6.0+ on runtime. We originally saw the test failure in EPEL 9 (has expat 2.5.0 with some security backports), when we updated to Python 3.13.15. I used LLM to analyze the cause of the test failure. [1] https://github.com/python/cpython/blob/v3.15.0rc1/Modules/pyexpat.c#L847-L850 [2] https://github.com/python/cpython/blob/v3.15.0rc1/Modules/pyexpat.c#L1529 [3] https://github.com/python/cpython/blob/v3.15.0rc1/Modules/pyexpat.c#L858 Assisted-By: Claude Opus 4.6
1 parent a7541c3 commit ff8ae30

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

Lib/test/test_pyexpat.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,13 @@ def test_parent_parser_outlives_its_subparsers__chain(self):
10451045
del parser
10461046
del subparser
10471047

1048+
# gh-155485: GetReparseDeferralEnabled always returns False with Expat <2.6.0.
1049+
# Hence, we skip this test when pyxepat was compiled with Expat <2.6.0.
1050+
# We check the default value on a new parser instance to detect
1051+
# the compile-time expat version, rather than checking expat.version_info
1052+
# which stores the runtime expat version (to avoid problems like gh-144739).
1053+
@unittest.skipIf(not expat.ParserCreate().GetReparseDeferralEnabled(),
1054+
"requires Python compiled with Expat >= 2.6.0")
10481055
def test_subparser_inherits_reparse_deferral(self):
10491056
for enabled in (True, False):
10501057
parser = expat.ParserCreate()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Skip ``test_subparser_inherits_reparse_deferral`` in ``test_pyexpat`` when
2+
Python was compiled against Expat < 2.6.0.
3+
:meth:`~xml.parsers.expat.xmlparser.GetReparseDeferralEnabled`
4+
always returns false with this Expat version and hence the test does not work.

0 commit comments

Comments
 (0)