Always raise warnings for deprecated feature checks by radarhere · Pull Request #8459 · python-pillow/Pillow
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.
| 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.