mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Don't load setuptools plugins during test runs
Uses pattern from https://docs.pytest.org/en/latest/example/simple.html#detect-if-running-from-within-a-pytest-run Closes #438
This commit is contained in:
parent
033cf0bcbb
commit
f553a67021
2 changed files with 16 additions and 17 deletions
|
|
@ -1,15 +1,16 @@
|
||||||
import importlib
|
import importlib
|
||||||
import pluggy
|
import pluggy
|
||||||
|
import sys
|
||||||
from . import hookspecs
|
from . import hookspecs
|
||||||
|
|
||||||
DEFAULT_PLUGINS = (
|
DEFAULT_PLUGINS = ("datasette.publish.heroku", "datasette.publish.now")
|
||||||
"datasette.publish.heroku",
|
|
||||||
"datasette.publish.now",
|
|
||||||
)
|
|
||||||
|
|
||||||
pm = pluggy.PluginManager("datasette")
|
pm = pluggy.PluginManager("datasette")
|
||||||
pm.add_hookspecs(hookspecs)
|
pm.add_hookspecs(hookspecs)
|
||||||
pm.load_setuptools_entrypoints("datasette")
|
|
||||||
|
if not hasattr(sys, "_called_from_test"):
|
||||||
|
# Only load plugins if not running tests
|
||||||
|
pm.load_setuptools_entrypoints("datasette")
|
||||||
|
|
||||||
# Load default plugins
|
# Load default plugins
|
||||||
for plugin in DEFAULT_PLUGINS:
|
for plugin in DEFAULT_PLUGINS:
|
||||||
|
|
|
||||||
|
|
@ -1060,18 +1060,16 @@ def test_inspect_json(app_client):
|
||||||
|
|
||||||
|
|
||||||
def test_plugins_json(app_client):
|
def test_plugins_json(app_client):
|
||||||
response = app_client.get(
|
response = app_client.get("/-/plugins.json")
|
||||||
"/-/plugins.json"
|
assert [
|
||||||
)
|
{"name": "my_plugin.py", "static": False, "templates": False, "version": None},
|
||||||
# This will include any plugins that have been installed into the
|
{
|
||||||
# current virtual environment, so we only check for the presence of
|
"name": "my_plugin_2.py",
|
||||||
# the one we know will definitely be There
|
"static": False,
|
||||||
assert {
|
"templates": False,
|
||||||
'name': 'my_plugin.py',
|
"version": None,
|
||||||
'static': False,
|
}
|
||||||
'templates': False,
|
] == sorted(response.json, key=lambda p: p["name"])
|
||||||
'version': None,
|
|
||||||
} in response.json
|
|
||||||
|
|
||||||
|
|
||||||
def test_versions_json(app_client):
|
def test_versions_json(app_client):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue