Repository navigation
test_re fails on Alpine Linux (with musl) #131342
Copy link
Copy link
Closed
Labels
OS-unsupportedtestsTests in the Lib/test dirTests in the Lib/test dirtopic-regextype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
718.6 0:01:10 load avg: 0.97 [35/44] test_re
719.7 test test_re failed
719.7 0:01:11 load avg: 0.98 [36/44] test_set -- test_re failed (2 failures)
724.7 0:01:16 load avg: 0.98 [37/44] test_sqlite3
725.6 0:01:17 load avg: 0.98 [38/44] test_statistics
733.0 0:01:24 load avg: 0.98 [39/44] test_str
735.1 0:01:26 load avg: 0.98 [40/44] test_struct
735.8 0:01:27 load avg: 0.98 [41/44] test_tabnanny
736.3 0:01:28 load avg: 0.98 [42/44] test_time
739.5 0:01:31 load avg: 0.98 [43/44] test_xml_etree
740.2 0:01:32 load avg: 0.98 [44/44] test_xml_etree_c
741.3
741.3 Total duration: 1 min 33 sec
741.3 Total tests: run=9,178 failures=3 skipped=203
741.3 Total test files: run=44/44 failed=2 skipped=2
741.3 Result: FAILURE
741.3 make: *** [Makefile:886: profile-run-stamp] Error 2
And while running in verbose mode the following is the output of it.
./python -m unittest -v test.test_re
(...)
======================================================================
FAIL: test_locale_caching (test.test_re.ReTests.test_locale_caching)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Python-3.13.2/Lib/test/test_re.py", line 2195, in test_locale_caching
self.check_en_US_iso88591()
~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/Python-3.13.2/Lib/test/test_re.py", line 2204, in check_en_US_iso88591
self.assertTrue(re.match(b'\xc5', b'\xe5', re.L|re.I))
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None is not true
======================================================================
FAIL: test_locale_compiled (test.test_re.ReTests.test_locale_compiled)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Python-3.13.2/Lib/test/test_re.py", line 2240, in test_locale_compiled
self.assertTrue(p.match(b'\xe5\xe5'))
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None is not true
----------------------------------------------------------------------
Ran 165 tests in 0.838s
FAILED (failures=2, skipped=1)CPython versions tested on:
3.13
Operating systems tested on:
Linux
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
OS-unsupportedtestsTests in the Lib/test dirTests in the Lib/test dirtopic-regextype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsDone
Activity
[-]test_locale_caching and test_locale_compiled failing while installing python3.13[/-][+]test_re fails on Alpine Linux (with musl)[/+]StanFromIreland commentedon Mar 17, 2025
Do you have
en_US_iso88591installed? Check with:locale -a | grep en_USBoth of the tests depend on it.
I presume it is setting a locale that is not available for some reason.
I am unable to reproduce after deleting locale:
vstinner commentedon Mar 17, 2025
@StanFromIreland: Do you link Python to the musl C library?
StanFromIreland commentedon Mar 17, 2025
@vstinner: I should have specified, I did not. I am not sure whether it is even packaged for Fedora.
vstinner commentedon Mar 17, 2025
musl is package in Fedora, but I failed to build Python using musl-gcc wrapper. I built Python in Alpine to get musl.
serhiy-storchaka commentedon Mar 17, 2025
Please add the following lines at the beginning of
test_locale_compiled()and show the output.vstinner commentedon Mar 17, 2025
Here you have:
vstinner commentedon Mar 17, 2025
Using musl, setlocale() doesn't fail even if the locale isn't supported:
Another example:
vstinner commentedon Mar 17, 2025
See also #131313
StanFromIreland commentedon Mar 17, 2025
The PR covers both the tests here already. I guess the PR can be assigned this issue?
deepwzh commentedon Mar 17, 2025
I have roughly identified the reasons:
en_US_iso88591encoding by default.setlocalefunction in musl and glibc are inconsistent. For musl, passing any value will not cause an error. Therefore, even iflocale.setlocale(locale.LC_CTYPE, 'en_US.iso88591')does not throw an exception, it will not work properly.When I run the code in two environments, the behavior is different
glibc:
musl:
No error is thrown.
Further, you can refer to the musl source code here:
https://github.com/bminor/musl/blob/c47ad25ea3b484e10326f933e927c0bc8cded3da/src/locale/locale_map.c#L99
From this, it can be seen that if a non-existent locale is passed, it will actually default to UTF-8 encoding instead of throwing an error.
vstinner commentedon Mar 17, 2025
PR #131313 was assigned to the older issue #90548.
vstinner commentedon Mar 19, 2025
Issue fixed by change 6146295.