⚡ Solution Summary
- Tests using pkgutil.get_loader should be removed
- The search code now uses importlib
- Ensure compatibility with Python 3.14
- Review test cases for relevance.
Per What's new in Python 3.14:
> Remove deprecated pkgutil.get_loader() and pkgutil.find_loader(). These had previously raised a DeprecationWarning since Python 3.12. (Contributed by Bénédikt Tran in gh-97850.)
It manifests in flask's tests:
```
______________ ERROR at setup of test_prefix_package_paths[True] _______________
request = <SubRequest 'limit_loader' for <Function test_prefix_package_paths[True]>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f1fe6cb9b70>
@pytest.fixture(params=(True, False))
def limit_loader(request, monkeypatch):
"""Patch pkgutil.get_loader to give loader without get_filename or archive.
This provides for tests where a system has custom loaders, e.g. Google App
Engine's HardenedModulesHook, which have neither the `get_filename` method
nor the `archive` attribute.
This fixture will run the testcase twice, once with and once without the
limitation/mock.
"""
if not request.param:
return
class LimitedLoader:
def __init__(self, loader):
self.loader = loader
def __getattr__(self, name):
if name in {"archive", "get_filename"}:
raise AttributeError(f"Mocking a loader which does not have {name!r}.")
return getattr(self.loader, name)
> old_get_loader = pkgutil.get_loader
E AttributeError: module 'pkgutil' has no attribute 'get_loader'
ERROR tests/test_instance_config.py::test_installed_module_paths[True] - Attr...
ERROR tests/test_instance_config.py::test_installed_package_paths[True] - Att...
ERROR tests/test_instance_config.py::test_prefix_package_paths[True] - Attrib...
```
Run the tests with Python 3.14
Environment:
- Python version: 3.14.0a6
- Flask version: 3.1.0
Discussion & Fixes