Closed simonw closed 2 months ago
That's annoying: this pattern doesn't work:
from django.test.client import Client
import djp
def test_django_plugins():
class TestPlugin:
__name__ = "TestPlugin"
@djp.hookimpl
def installed_apps(self):
return [
"tests.test_project.app1"
]
@djp.hookimpl
def middleware(self):
return [
"tests.test_project.middleware.Middleware",
djp.Before("tests.test_project.middleware.MiddlewareBefore"),
djp.After("tests.test_project.middleware.MiddlewareAfter"),
]
djp.pm.register(TestPlugin(), name="undo")
try:
response = Client().get("/")
request = response._request
assert hasattr(request, "_notes")
finally:
djp.pm.unregister(name="undo")
Because the plugin hooks are only run once when settings.py
is first invoked, so modifying plugins in this way has no impact.
So I need to figure out how to put an example plugin somewhere in tests/
and have that loaded when pytest
runs but not the rest of the time.
Need automated tests against each of the plugin hooks.
I've already figured out patterns for this in these two plugins: