diff --git a/tests/integrations/django/myapp/management/__init__.py b/tests/integrations/django/myapp/management/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integrations/django/myapp/management/commands/__init__.py b/tests/integrations/django/myapp/management/commands/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integrations/django/myapp/management/commands/mycrash.py b/tests/integrations/django/myapp/management/commands/mycrash.py new file mode 100644 index 0000000000..48764d904a --- /dev/null +++ b/tests/integrations/django/myapp/management/commands/mycrash.py @@ -0,0 +1,9 @@ +from django.core.management.base import BaseCommand + + +class Command(BaseCommand): + def add_arguments(self, parser): + pass + + def handle(self, *args, **options): + 1 / 0 diff --git a/tests/integrations/django/myapp/settings.py b/tests/integrations/django/myapp/settings.py index 27e880d1d7..cde0cb13c0 100644 --- a/tests/integrations/django/myapp/settings.py +++ b/tests/integrations/django/myapp/settings.py @@ -48,6 +48,7 @@ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", + "tests.integrations.django.myapp", ] diff --git a/tests/integrations/django/test_basic.py b/tests/integrations/django/test_basic.py index e0cd425074..56fa7c416f 100644 --- a/tests/integrations/django/test_basic.py +++ b/tests/integrations/django/test_basic.py @@ -4,6 +4,7 @@ from django.test import Client +from django.core.management import execute_from_command_line try: from django.urls import reverse @@ -79,3 +80,11 @@ def test_user_captured(client, capture_events): def test_404(client): response = client.get("/404") assert response.status_code == 404 + + +def test_management_command_raises(): + # This just checks for our assumption that Django passes through all + # exceptions by default, so our excepthook can be used for management + # commands. + with pytest.raises(ZeroDivisionError): + execute_from_command_line(["manage.py", "mycrash"]) diff --git a/tests/integrations/flask/test_flask.py b/tests/integrations/flask/test_flask.py index 85a007e0d5..cb5b78385e 100644 --- a/tests/integrations/flask/test_flask.py +++ b/tests/integrations/flask/test_flask.py @@ -324,3 +324,19 @@ def index(): def test_no_errors_without_request(app): with app.app_context(): capture_exception(ValueError()) + + +def test_cli_commands_raise(app): + if not hasattr(app, "cli"): + pytest.skip("Too old flask version") + + from flask.cli import ScriptInfo + + @app.cli.command() + def foo(): + 1 / 0 + + with pytest.raises(ZeroDivisionError): + app.cli.main( + args=["foo"], prog_name="myapp", obj=ScriptInfo(create_app=lambda _: app) + )