-
-
Notifications
You must be signed in to change notification settings - Fork 691
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs on temporary plugins in fixtures, closes #2234
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# fmt: off | ||
# -- start datasette_with_plugin_fixture -- | ||
from datasette import hookimpl | ||
from datasette.app import Datasette | ||
from datasette.plugins import pm | ||
import pytest | ||
import pytest_asyncio | ||
|
||
|
||
@pytest_asyncio.fixture | ||
async def datasette_with_plugin(): | ||
class TestPlugin: | ||
__name__ = "TestPlugin" | ||
|
||
@hookimpl | ||
def register_routes(self): | ||
return [ | ||
(r"^/error$", lambda: 1 / 0), | ||
] | ||
|
||
pm.register(TestPlugin(), name="undo") | ||
try: | ||
yield Datasette() | ||
finally: | ||
pm.unregister(name="undo") | ||
# -- end datasette_with_plugin_fixture -- | ||
|
||
|
||
# -- start datasette_with_plugin_test -- | ||
@pytest.mark.asyncio | ||
async def test_error(datasette_with_plugin): | ||
response = await datasette_with_plugin.client.get("/error") | ||
assert response.status_code == 500 | ||
# -- end datasette_with_plugin_test -- |