remove tests about deprecated pkgutil.get_loader

This commit is contained in:
David Lord 2025-03-29 15:42:58 -07:00
parent 2732c4db66
commit 41ec5760a2
No known key found for this signature in database
GPG key ID: 43368A7AA8CC5926
2 changed files with 3 additions and 35 deletions

View file

@ -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."""