Skip to content

fix: Plugins are still loaded when running tests#719

Merged
simonw merged 2 commits into
simonw:mainfrom
RamiNoodle733:fix/issue-713
Jun 21, 2026
Merged

fix: Plugins are still loaded when running tests#719
simonw merged 2 commits into
simonw:mainfrom
RamiNoodle733:fix/issue-713

Conversation

@RamiNoodle733

@RamiNoodle733 RamiNoodle733 commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Plugin entrypoints were being loaded at module import time, before tests set sys._called_from_test, which allowed system-installed plugins to leak into test runs. This change defers entrypoint loading until plugin hooks are actually used, and only when not running tests.

Changes

  • Added ensure_plugins_loaded() and a one-time _plugins_loaded guard in sqlite_utils/plugins.py
  • Updated Database.__init__() to call ensure_plugins_loaded() before prepare_connection hooks
  • Updated cli.py to call ensure_plugins_loaded() before register_commands hooks

Testing

  • Created a virtualenv and ran: pytest -q tests/test_plugins.py
  • Result: 2 passed

Fixes #713


📚 Documentation preview 📚: https://sqlite-utils--719.org.readthedocs.build/en/719/

RamiNoodle733 and others added 2 commits March 7, 2026 18:33
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.
Copilot AI review requested due to automatic review settings June 21, 2026 23:14
@simonw simonw merged commit f448b61 into simonw:main Jun 21, 2026
4 of 96 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes leakage of system-installed plugins into the test suite by deferring setuptools entrypoint loading until plugin hooks are actually needed, and skipping that loading entirely when tests are running (sys._called_from_test).

Changes:

  • Introduces ensure_plugins_loaded() with a one-time _plugins_loaded guard and calls it from get_plugins().
  • Ensures plugins are loaded (when appropriate) immediately before prepare_connection and register_commands hooks are invoked.
  • Adds targeted tests verifying entrypoints load once in non-test mode and never load during tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
tests/test_plugins.py Adds regression tests for one-time entrypoint loading and “never load in tests” behavior.
sqlite_utils/plugins.py Moves entrypoint loading behind ensure_plugins_loaded() and calls it from get_plugins().
sqlite_utils/db.py Loads plugins right before invoking prepare_connection hooks in Database.__init__().
sqlite_utils/cli.py Loads plugins right before invoking register_commands hooks during CLI module initialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

simonw added a commit that referenced this pull request Jun 21, 2026
simonw added a commit that referenced this pull request Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugins are still loaded when running tests

3 participants