Skip to content

Commit

Permalink
docs: Added debug=True in Testing to display exception stack trace (#…
Browse files Browse the repository at this point in the history
…3860)

* docs: added `debug==True` in Testing to display exception stack trace

* docs: ruff-format

* docs: add `app.debug = True` to the fixture sample code
  • Loading branch information
RenameMe1 authored Nov 17, 2024
1 parent a2b8e48 commit 1b2ef9a
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/examples/testing/test_get_session_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def set_session_data(request: Request) -> None:
request.session["foo"] = "bar"


app = Litestar(route_handlers=[set_session_data], middleware=[session_config.middleware])
app = Litestar(route_handlers=[set_session_data], middleware=[session_config.middleware], debug=True)

with TestClient(app=app, session_config=session_config) as client:
client.post("/test").json()
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/testing/test_get_session_data_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def set_session_data(request: Request) -> None:
request.session["foo"] = "bar"


app = Litestar(route_handlers=[set_session_data], middleware=[session_config.middleware])
app = Litestar(route_handlers=[set_session_data], middleware=[session_config.middleware], debug=True)


async def test_set_session_data() -> None:
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/testing/test_health_check_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def health_check() -> str:
return "healthy"


app = Litestar(route_handlers=[health_check])
app = Litestar(route_handlers=[health_check], debug=True)


@pytest.fixture(scope="function")
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/testing/test_health_check_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def health_check() -> str:
return "healthy"


app = Litestar(route_handlers=[health_check])
app = Litestar(route_handlers=[health_check], debug=True)


@pytest.fixture(scope="function")
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/testing/test_set_session_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_session_data(request: Request) -> Dict[str, Any]:
return request.session


app = Litestar(route_handlers=[get_session_data], middleware=[session_config.middleware])
app = Litestar(route_handlers=[get_session_data], middleware=[session_config.middleware], debug=True)


def test_get_session_data() -> None:
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/testing/test_set_session_data_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_session_data(request: Request) -> Dict[str, Any]:
return request.session


app = Litestar(route_handlers=[get_session_data], middleware=[session_config.middleware])
app = Litestar(route_handlers=[get_session_data], middleware=[session_config.middleware], debug=True)


async def test_get_session_data() -> None:
Expand Down
8 changes: 8 additions & 0 deletions docs/usage/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ We would then test it using the test client like so:
from my_app.main import app
app.debug = True
def test_health_check():
with TestClient(app=app) as client:
Expand All @@ -60,6 +62,8 @@ We would then test it using the test client like so:
from my_app.main import app
app.debug = True
async def test_health_check():
async with AsyncTestClient(app=app) as client:
Expand Down Expand Up @@ -90,6 +94,8 @@ Since we would probably need to use the client in multiple places, it's better t
if TYPE_CHECKING:
from litestar import Litestar
app.debug = True
@pytest.fixture(scope="function")
def test_client() -> Iterator[TestClient[Litestar]]:
Expand All @@ -114,6 +120,8 @@ Since we would probably need to use the client in multiple places, it's better t
if TYPE_CHECKING:
from litestar import Litestar
app.debug = True
@pytest.fixture(scope="function")
async def test_client() -> AsyncIterator[AsyncTestClient[Litestar]]:
Expand Down

0 comments on commit 1b2ef9a

Please sign in to comment.