fix: Plugins are still loaded when running tests (#719)

* fix: defer plugin entrypoint loading until runtime

Fixes simonw/sqlite-utils#713

* Lazy-load plugins when listing them

Keep plugin entrypoints from loading at module import time, but preserve the existing behavior of get_plugins() by loading entrypoints the first time plugins are listed outside tests.

---------

Co-authored-by: Simon Willison <swillison@gmail.com>
This commit is contained in:
Rami Abdelrazzaq 2026-06-21 18:14:45 -05:00 committed by GitHub
commit f448b61f5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 4 deletions

View file

@ -6,13 +6,19 @@ from . import hookspecs
pm: pluggy.PluginManager = pluggy.PluginManager("sqlite_utils")
pm.add_hookspecs(hookspecs)
_plugins_loaded = False
if not getattr(sys, "_called_from_test", False):
# Only load plugins if not running tests
def ensure_plugins_loaded() -> None:
global _plugins_loaded
if _plugins_loaded or getattr(sys, "_called_from_test", False):
return
pm.load_setuptools_entrypoints("sqlite_utils")
_plugins_loaded = True
def get_plugins() -> List[Dict[str, Union[str, List[str]]]]:
ensure_plugins_loaded()
plugins: List[Dict[str, Union[str, List[str]]]] = []
plugin_to_distinfo = dict(pm.list_plugin_distinfo())
for plugin in pm.get_plugins():