pypa / packaging

Core utilities for Python packages
https://packaging.pypa.io/
Other
621 stars 250 forks source link

Test suite fails if running on Linux/musl #850

Open rossburton opened 3 weeks ago

rossburton commented 3 weeks ago

If I run the test suite on a system which is linux/musl based, then it fails:

FAILED tests/test_manylinux.py::test_is_manylinux_compatible_old - AssertionError: assert False
FAILED tests/test_tags.py::TestManylinuxPlatform::test_linux_platforms_manylinux_unsupported - AssertionError: assert ['musllinux_1...linux_x86_64'] == ['linux_x86_64']
FAILED tests/test_tags.py::TestManylinuxPlatform::test_linux_platforms_manylinux1 - AssertionError: assert ['manylinux_2...linux_x86_64'] == ['manylinux_2...linux_x86_64']
FAILED tests/test_tags.py::TestManylinuxPlatform::test_linux_platforms_manylinux2010 - AssertionError: assert ['manylinux_2..._x86_64', ...] == ['manylinux_2..._x86_64', ...]
FAILED tests/test_tags.py::TestManylinuxPlatform::test_linux_platforms_manylinux2014 - AssertionError: assert ['manylinux_2..._x86_64', ...] == ['manylinux_2..._x86_64', ...]
FAILED tests/test_tags.py::TestManylinuxPlatform::test_linux_platforms_manylinux2014_armv6l - AssertionError: assert ['musllinux_1...linux_armv6l'] == ['linux_armv6l']
FAILED tests/test_tags.py::TestSysTags::test_linux_platforms_manylinux2014_armv6l - AssertionError: assert ['musllinux_1...linux_armv6l'] == ['linux_armv6l']
FAILED tests/test_tags.py::TestSysTags::test_skip_manylinux_2014 - AssertionError: assert ['manylinux_2...0_ppc64', ...] == ['manylinux_2...'linux_ppc64']
FAILED tests/test_tags.py::TestSysTags::test_linux_use_manylinux_compatible[x86_64-2-20-False] - AssertionError: assert ['musllinux_1...linux_x86_64'] == ['linux_x86_64']
FAILED tests/test_tags.py::TestSysTags::test_linux_use_manylinux_compatible[s390x-2-22-True] - AssertionError: assert ['manylinux_2...'linux_s390x'] == ['manylinux_2...'linux_s390x']
FAILED tests/test_tags.py::TestSysTags::test_linux_use_manylinux_compatible_none - AssertionError: assert ['manylinux_2..._x86_64', ...] == ['manylinux_2..._x86_64', ...]
rossburton commented 3 weeks ago
Full failure log: ``` =============================================================== FAILURES ================================================================ ___________________________________________________ test_is_manylinux_compatible_old ____________________________________________________ @pytest.mark.skipif(platform.system() != "Linux", reason="requires Linux") def test_is_manylinux_compatible_old(): # Assuming no one is running this test with a version of glibc released in # 1997. > assert _is_compatible("any", (2, 0)) E AssertionError: assert False E + where False = _is_compatible('any', (2, 0)) tests/test_manylinux.py:156: AssertionError ___________________________________ TestManylinuxPlatform.test_linux_platforms_manylinux_unsupported ____________________________________ self = monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0xffffa2869e10> def test_linux_platforms_manylinux_unsupported(self, monkeypatch): monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False) monkeypatch.setattr(tags._manylinux, "_is_compatible", lambda *args: False) linux_platform = list(tags._linux_platforms(is_32bit=False)) > assert linux_platform == ["linux_x86_64"] E AssertionError: assert ['musllinux_1...linux_x86_64'] == ['linux_x86_64'] E E At index 0 diff: 'musllinux_1_2_x86_64' != 'linux_x86_64' E Left contains 3 more items, first extra item: 'musllinux_1_1_x86_64' E Use -v to get more diff tests/test_tags.py:387: AssertionError _________________________________________ TestManylinuxPlatform.test_linux_platforms_manylinux1 _________________________________________ self = monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0xffffa2b15160> def test_linux_platforms_manylinux1(self, monkeypatch): monkeypatch.setattr( tags._manylinux, "_is_compatible", lambda _, glibc_version: glibc_version == _GLibCVersion(2, 5), ) monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64") monkeypatch.setattr(platform, "machine", lambda: "x86_64") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False) platforms = list(tags._linux_platforms(is_32bit=False)) > assert platforms == [ "manylinux_2_5_x86_64", "manylinux1_x86_64", "linux_x86_64", ] E AssertionError: assert ['manylinux_2...linux_x86_64'] == ['manylinux_2...linux_x86_64'] E E At index 2 diff: 'musllinux_1_2_x86_64' != 'linux_x86_64' E Left contains 3 more items, first extra item: 'musllinux_1_1_x86_64' E Use -v to get more diff tests/test_tags.py:399: AssertionError _______________________________________ TestManylinuxPlatform.test_linux_platforms_manylinux2010 ________________________________________ self = monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0xffffa2b14520> def test_linux_platforms_manylinux2010(self, monkeypatch): monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64") monkeypatch.setattr(platform, "machine", lambda: "x86_64") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.12", raising=False) platforms = list(tags._linux_platforms(is_32bit=False)) expected = [ "manylinux_2_12_x86_64", "manylinux2010_x86_64", "manylinux_2_11_x86_64", "manylinux_2_10_x86_64", "manylinux_2_9_x86_64", "manylinux_2_8_x86_64", "manylinux_2_7_x86_64", "manylinux_2_6_x86_64", "manylinux_2_5_x86_64", "manylinux1_x86_64", "linux_x86_64", ] > assert platforms == expected E AssertionError: assert ['manylinux_2..._x86_64', ...] == ['manylinux_2..._x86_64', ...] E E At index 10 diff: 'musllinux_1_2_x86_64' != 'linux_x86_64' E Left contains 3 more items, first extra item: 'musllinux_1_1_x86_64' E Use -v to get more diff tests/test_tags.py:423: AssertionError _______________________________________ TestManylinuxPlatform.test_linux_platforms_manylinux2014 ________________________________________ self = monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0xffffa2b156a0> def test_linux_platforms_manylinux2014(self, monkeypatch): monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64") monkeypatch.setattr(platform, "machine", lambda: "x86_64") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.17", raising=False) platforms = list(tags._linux_platforms(is_32bit=False)) arch = platform.machine() expected = [ "manylinux_2_17_" + arch, "manylinux2014_" + arch, "manylinux_2_16_" + arch, "manylinux_2_15_" + arch, "manylinux_2_14_" + arch, "manylinux_2_13_" + arch, "manylinux_2_12_" + arch, "manylinux2010_" + arch, "manylinux_2_11_" + arch, "manylinux_2_10_" + arch, "manylinux_2_9_" + arch, "manylinux_2_8_" + arch, "manylinux_2_7_" + arch, "manylinux_2_6_" + arch, "manylinux_2_5_" + arch, "manylinux1_" + arch, "linux_" + arch, ] > assert platforms == expected E AssertionError: assert ['manylinux_2..._x86_64', ...] == ['manylinux_2..._x86_64', ...] E E At index 16 diff: 'musllinux_1_2_x86_64' != 'linux_x86_64' E Left contains 3 more items, first extra item: 'musllinux_1_1_x86_64' E Use -v to get more diff tests/test_tags.py:450: AssertionError ____________________________________ TestManylinuxPlatform.test_linux_platforms_manylinux2014_armv6l ____________________________________ self = monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0xffffa286be70> def test_linux_platforms_manylinux2014_armv6l(self, monkeypatch): monkeypatch.setattr( tags._manylinux, "_is_compatible", lambda _, glibc_version: glibc_version == _GLibCVersion(2, 17), ) monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_armv6l") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False) platforms = list(tags._linux_platforms(is_32bit=True)) expected = ["linux_armv6l"] > assert platforms == expected E AssertionError: assert ['musllinux_1...linux_armv6l'] == ['linux_armv6l'] E E At index 0 diff: 'musllinux_1_2_armv6l' != 'linux_armv6l' E Left contains 3 more items, first extra item: 'musllinux_1_1_armv6l' E Use -v to get more diff tests/test_tags.py:588: AssertionError _________________________________________ TestSysTags.test_linux_platforms_manylinux2014_armv6l _________________________________________ self = , monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0xffffa284c0c0> manylinux_module = def test_linux_platforms_manylinux2014_armv6l(self, monkeypatch, manylinux_module): monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_armv6l") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False) platforms = list(tags._linux_platforms(is_32bit=True)) expected = ["linux_armv6l"] > assert platforms == expected E AssertionError: assert ['musllinux_1...linux_armv6l'] == ['linux_armv6l'] E E At index 0 diff: 'musllinux_1_2_armv6l' != 'linux_armv6l' E Left contains 3 more items, first extra item: 'musllinux_1_1_armv6l' E Use -v to get more diff tests/test_tags.py:1246: AssertionError _________________________________________________ TestSysTags.test_skip_manylinux_2014 __________________________________________________ self = , monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0xffffa28c8520> manylinux_module = def test_skip_manylinux_2014(self, monkeypatch, manylinux_module): monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_ppc64") monkeypatch.setattr(tags._manylinux, "_get_glibc_version", lambda: (2, 20)) monkeypatch.setattr( manylinux_module, "manylinux2014_compatible", False, raising=False ) expected = [ "manylinux_2_20_ppc64", "manylinux_2_19_ppc64", "manylinux_2_18_ppc64", # "manylinux2014_ppc64", # this one is skipped # "manylinux_2_17_ppc64", # this one is also skipped "linux_ppc64", ] platforms = list(tags._linux_platforms()) > assert platforms == expected E AssertionError: assert ['manylinux_2...0_ppc64', ...] == ['manylinux_2...'linux_ppc64'] E E At index 3 diff: 'musllinux_1_2_ppc64' != 'linux_ppc64' E Left contains 3 more items, first extra item: 'musllinux_1_1_ppc64' E Use -v to get more diff tests/test_tags.py:1263: AssertionError __________________________________ TestSysTags.test_linux_use_manylinux_compatible[x86_64-2-20-False] ___________________________________ self = , monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0xffffa2893af0> manylinux_module = , machine = 'x86_64', major = 2, minor = 20, tf = False @pytest.mark.parametrize( "machine, major, minor, tf", [("x86_64", 2, 20, False), ("s390x", 2, 22, True)] ) def test_linux_use_manylinux_compatible( self, monkeypatch, manylinux_module, machine, major, minor, tf ): def manylinux_compatible(tag_major, tag_minor, tag_arch): if tag_major == 2 and tag_minor == 22: return tag_arch == "s390x" return False monkeypatch.setattr( tags._manylinux, "_get_glibc_version", lambda: (major, minor), ) monkeypatch.setattr(sysconfig, "get_platform", lambda: f"linux_{machine}") monkeypatch.setattr( manylinux_module, "manylinux_compatible", manylinux_compatible, raising=False, ) platforms = list(tags._linux_platforms(is_32bit=False)) if tf: expected = [f"manylinux_2_22_{machine}"] else: expected = [] expected.append(f"linux_{machine}") > assert platforms == expected E AssertionError: assert ['musllinux_1...linux_x86_64'] == ['linux_x86_64'] E E At index 0 diff: 'musllinux_1_2_x86_64' != 'linux_x86_64' E Left contains 3 more items, first extra item: 'musllinux_1_1_x86_64' E Use -v to get more diff tests/test_tags.py:1315: AssertionError ___________________________________ TestSysTags.test_linux_use_manylinux_compatible[s390x-2-22-True] ____________________________________ self = , monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0xffffa28924a0> manylinux_module = , machine = 's390x', major = 2, minor = 22, tf = True @pytest.mark.parametrize( "machine, major, minor, tf", [("x86_64", 2, 20, False), ("s390x", 2, 22, True)] ) def test_linux_use_manylinux_compatible( self, monkeypatch, manylinux_module, machine, major, minor, tf ): def manylinux_compatible(tag_major, tag_minor, tag_arch): if tag_major == 2 and tag_minor == 22: return tag_arch == "s390x" return False monkeypatch.setattr( tags._manylinux, "_get_glibc_version", lambda: (major, minor), ) monkeypatch.setattr(sysconfig, "get_platform", lambda: f"linux_{machine}") monkeypatch.setattr( manylinux_module, "manylinux_compatible", manylinux_compatible, raising=False, ) platforms = list(tags._linux_platforms(is_32bit=False)) if tf: expected = [f"manylinux_2_22_{machine}"] else: expected = [] expected.append(f"linux_{machine}") > assert platforms == expected E AssertionError: assert ['manylinux_2...'linux_s390x'] == ['manylinux_2...'linux_s390x'] E E At index 1 diff: 'musllinux_1_2_s390x' != 'linux_s390x' E Left contains 3 more items, first extra item: 'musllinux_1_1_s390x' E Use -v to get more diff tests/test_tags.py:1315: AssertionError _________________________________________ TestSysTags.test_linux_use_manylinux_compatible_none __________________________________________ self = , monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0xffffa2891940> manylinux_module = def test_linux_use_manylinux_compatible_none(self, monkeypatch, manylinux_module): def manylinux_compatible(tag_major, tag_minor, tag_arch): if tag_major == 2 and tag_minor < 25: return False return None monkeypatch.setattr(tags._manylinux, "_get_glibc_version", lambda: (2, 30)) monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64") monkeypatch.setattr( manylinux_module, "manylinux_compatible", manylinux_compatible, raising=False, ) platforms = list(tags._linux_platforms(is_32bit=False)) expected = [ "manylinux_2_30_x86_64", "manylinux_2_29_x86_64", "manylinux_2_28_x86_64", "manylinux_2_27_x86_64", "manylinux_2_26_x86_64", "manylinux_2_25_x86_64", "linux_x86_64", ] > assert platforms == expected E AssertionError: assert ['manylinux_2..._x86_64', ...] == ['manylinux_2..._x86_64', ...] E E At index 6 diff: 'musllinux_1_2_x86_64' != 'linux_x86_64' E Left contains 3 more items, first extra item: 'musllinux_1_1_x86_64' E Use -v to get more diff tests/test_tags.py:1341: AssertionError ======================================================== short test summary info ======================================================== FAILED tests/test_manylinux.py::test_is_manylinux_compatible_old - AssertionError: assert False FAILED tests/test_tags.py::TestManylinuxPlatform::test_linux_platforms_manylinux_unsupported - AssertionError: assert ['musllinux_1...linux_x86_64'] == ['linux_x86_64'] FAILED tests/test_tags.py::TestManylinuxPlatform::test_linux_platforms_manylinux1 - AssertionError: assert ['manylinux_2...linux_x86_64'] == ['manylinux_2...linux_x86_64'] FAILED tests/test_tags.py::TestManylinuxPlatform::test_linux_platforms_manylinux2010 - AssertionError: assert ['manylinux_2..._x86_64', ...] == ['manylinux_2..._x86_64', ...] FAILED tests/test_tags.py::TestManylinuxPlatform::test_linux_platforms_manylinux2014 - AssertionError: assert ['manylinux_2..._x86_64', ...] == ['manylinux_2..._x86_64', ...] FAILED tests/test_tags.py::TestManylinuxPlatform::test_linux_platforms_manylinux2014_armv6l - AssertionError: assert ['musllinux_1...linux_armv6l'] == ['linux_armv6l'] FAILED tests/test_tags.py::TestSysTags::test_linux_platforms_manylinux2014_armv6l - AssertionError: assert ['musllinux_1...linux_armv6l'] == ['linux_armv6l'] FAILED tests/test_tags.py::TestSysTags::test_skip_manylinux_2014 - AssertionError: assert ['manylinux_2...0_ppc64', ...] == ['manylinux_2...'linux_ppc64'] FAILED tests/test_tags.py::TestSysTags::test_linux_use_manylinux_compatible[x86_64-2-20-False] - AssertionError: assert ['musllinux_1...linux_x86_64'] == ['linux_x86_64'] FAILED tests/test_tags.py::TestSysTags::test_linux_use_manylinux_compatible[s390x-2-22-True] - AssertionError: assert ['manylinux_2...'linux_s390x'] == ['manylinux_2...'linux_s390x'] FAILED tests/test_tags.py::TestSysTags::test_linux_use_manylinux_compatible_none - AssertionError: assert ['manylinux_2..._x86_64', ...] == ['manylinux_2..._x86_64', ...] ```
brettcannon commented 3 weeks ago

What is probably happening is the following chunk of code isn't saying musllinux isn't available:

https://github.com/pypa/packaging/blob/029f41580098bcf52b69684843bdc7ea37959a7e/src/packaging/_musllinux.py#L67-L69

So probably need to monkeypatch _get_musl_version() to return None in these tests:

https://github.com/pypa/packaging/blob/029f41580098bcf52b69684843bdc7ea37959a7e/src/packaging/_musllinux.py#L34

It might be time to refactor the monkeypatching code to centralize it more so it's easier to turn on/off platform detection for tests.