Skip to content

Plugins are still loaded when running tests #713

Closed

Description

@radon-at-beeper

This code has the intention of only loading plugins when not running tests:

if not getattr(sys, "_called_from_test", False):
# Only load plugins if not running tests
pm.load_setuptools_entrypoints("sqlite_utils")

def pytest_configure(config):
import sys
sys._called_from_test = True # type: ignore[attr-defined]

However, as far as I can tell, it doesn't function as intended. Plugins are still loaded when running tests. For example, if the https://github.com/simonw/sqlite-migrate plugin is installed on the system, then running pytest fails with errors like this:

    def test_register_commands():
        importlib.reload(cli)
>       assert plugins.get_plugins() == []
E       AssertionError: assert [{'hooks': ['...on': '0.1b0'}] == []
E         
E         Left contains one more item: {'hooks': ['register_commands'], 'name': 'sqlite-migrate', 'version': '0.1b0'}
E         Use -v to get more diff

tests/test_plugins.py:9: AssertionError

As a result, downstream packaging is more difficult, e.g. https://aur.archlinux.org/packages/sqlite-utils#comment-1031481.

The error appears to be because getattr(sys, "_called_from_test", False) is called while loading sqlite_utils.plugins, not at runtime. However, sqlite_utils.plugins is loaded by sqlite_utils.db, which is loaded by sqlite_utils, which is loaded by conftest, so plugins are already loaded before pytest_configure is defined by conftest.

Activity

  1. added 2 commits that reference this issue on Mar 7, 2026
    00ac772
    974fe2f
  2. added 2 commits that reference this issue on Jun 21, 2026
  3. added a commit that references this issue on Jun 22, 2026
    f448b61
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions