Skip to content

Conversation

@radarhere
Copy link
Member

When I run the test suite without WebP installed, it fails.

Tests/test_features.py::test_check FAILED                                [  2%]

================================== FAILURES ===================================
_________________________________ test_check __________________________________

    def test_check() -> None:
        # Check the correctness of the convenience function
        for module in features.modules:
            assert features.check_module(module) == features.check(module)
        for codec in features.codecs:
            assert features.check_codec(codec) == features.check(codec)
        for feature in features.features:
            if "webp" in feature:
>               with pytest.warns(DeprecationWarning):
E               Failed: DID NOT WARN. No warnings of type (<class 'DeprecationWarning'>,) were emitted.
E                Emitted warnings: [].

The backstory of this is that #8213 deprecated features.check("transp_webp"), features.check("webp_mux") and features.check("webp_anim").

However, the deprecation warning is only raised if the underlying WebP module is installed, and the missing module doesn't raise an error earlier than the warning.

Pillow/src/PIL/features.py

Lines 149 to 159 in e93dcc1

try:
imported_module = __import__(module, fromlist=["PIL"])
if isinstance(flag, bool):
deprecate(f'check_feature("{feature}")', 12)
return flag
return getattr(imported_module, flag)
except ModuleNotFoundError:
return None
except ImportError as ex:
warnings.warn(str(ex))
return None

This PR updates features.py so that the feature checks raise a deprecation warning when WebP is not installed as well.

@radarhere radarhere added the WebP label Oct 11, 2024
@hugovk hugovk merged commit 08b561e into python-pillow:main Oct 11, 2024
@radarhere radarhere deleted the webp branch October 11, 2024 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants