https://github.com/pallets/flask/issues/5692 https://github.com/pallets/flask/pull/5702 From 41ec5760a2c55a099c3a1733fdd36fbb1258a02b Mon Sep 17 00:00:00 2001 From: David Lord Date: Sat, 29 Mar 2025 15:42:58 -0700 Subject: [PATCH] remove tests about deprecated pkgutil.get_loader --- tests/conftest.py | 32 -------------------------------- tests/test_instance_config.py | 6 +++--- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 58cf85d8a5..214f520338 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,4 @@ import os -import pkgutil import sys import pytest @@ -96,37 +95,6 @@ def leak_detector(): assert leaks == [] -@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 - - def get_loader(*args, **kwargs): - return LimitedLoader(old_get_loader(*args, **kwargs)) - - monkeypatch.setattr(pkgutil, "get_loader", get_loader) - - @pytest.fixture def modules_tmp_path(tmp_path, monkeypatch): """A temporary directory added to sys.path.""" diff --git a/tests/test_instance_config.py b/tests/test_instance_config.py index 1918bd999d..835a87844d 100644 --- a/tests/test_instance_config.py +++ b/tests/test_instance_config.py @@ -63,7 +63,7 @@ def create_namespace(package): def test_installed_module_paths( - modules_tmp_path, modules_tmp_path_prefix, purge_module, site_packages, limit_loader + modules_tmp_path, modules_tmp_path_prefix, purge_module, site_packages ): (site_packages / "site_app.py").write_text( "import flask\napp = flask.Flask(__name__)\n" @@ -78,7 +78,7 @@ def test_installed_module_paths( def test_installed_package_paths( - limit_loader, modules_tmp_path, modules_tmp_path_prefix, purge_module, monkeypatch + modules_tmp_path, modules_tmp_path_prefix, purge_module, monkeypatch ): installed_path = modules_tmp_path / "path" installed_path.mkdir() @@ -97,7 +97,7 @@ def test_installed_package_paths( def test_prefix_package_paths( - limit_loader, modules_tmp_path, modules_tmp_path_prefix, purge_module, site_packages + modules_tmp_path, modules_tmp_path_prefix, purge_module, site_packages ): app = site_packages / "site_package" app.mkdir()