Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions sqlite_utils/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
pm: pluggy.PluginManager = pluggy.PluginManager("sqlite_utils")
pm.add_hookspecs(hookspecs)

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

def _should_load_setuptools_plugins() -> bool:
# Avoid loading setuptools plugins while running test suites.
# Checking sys.modules for pytest makes this robust even if
# sys._called_from_test is set later during test initialization.
return not getattr(sys, "_called_from_test", False) and "pytest" not in sys.modules


if _should_load_setuptools_plugins():
pm.load_setuptools_entrypoints("sqlite_utils")


Expand Down
7 changes: 7 additions & 0 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import click
import importlib
import pytest
import sys
from sqlite_utils import cli, Database, hookimpl, plugins


Expand All @@ -16,6 +17,12 @@ def _supports_pragma_function_list():
db.close()


def test_should_not_load_setuptools_plugins_when_pytest_present(monkeypatch):
monkeypatch.delattr(sys, "_called_from_test", raising=False)
assert plugins._should_load_setuptools_plugins() is False



def test_register_commands():
importlib.reload(cli)
assert plugins.get_plugins() == []
Expand Down