File: test_application_after_exception_hook.py

package info (click to toggle)
litestar 2.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,568 kB
  • sloc: python: 70,588; makefile: 254; javascript: 104; sh: 60
file content (22 lines) | stat: -rw-r--r-- 741 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import logging
from typing import TYPE_CHECKING

import pytest
from docs.examples.application_hooks import after_exception_hook

from litestar.testing import TestClient

if TYPE_CHECKING:
    from _pytest.logging import LogCaptureFixture


@pytest.mark.usefixtures("reset_httpx_logging")
def test_application_shutdown_hooks(caplog: "LogCaptureFixture") -> None:
    with caplog.at_level(logging.INFO), TestClient(app=after_exception_hook.app) as client:
        assert len(caplog.messages) == 0
        client.get("/some-path")
        assert client.app.state.error_count == 1
        assert len(caplog.messages) == 1
        client.get("/some-path")
        assert client.app.state.error_count == 2
        assert len(caplog.messages) == 2