From 6fa1f7afff6d00d748610237ab0e0489c949662c Mon Sep 17 00:00:00 2001 From: SyntacticSalt Date: Fri, 6 Feb 2026 14:24:58 +0100 Subject: [PATCH 1/2] docs: Add information about terminal width for testing output Add instructions for checking rich output and setting terminal width in testing. --- docs/tutorial/testing.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/tutorial/testing.md b/docs/tutorial/testing.md index 66a189151b..911ec23afb 100644 --- a/docs/tutorial/testing.md +++ b/docs/tutorial/testing.md @@ -81,6 +81,24 @@ If you need a refresher about what is "standard output" and "standard error" che /// +#### Checking rich output + +Rich attempts to adjust the formatting to the connected terminal's size, wrapping or shortening content to make it fit. +However, in many test environments, there is no terminal attached to the process, and therefore Rich will fallback to a standard terminal width of 80 characters. + +In some cases this might not be sufficient to test the output of a command. +It is possible to override the width of a Rich `Console` object using the environment variable `COLUMNS`. +This applies to all instances of a console created in the application. + +Typer also creates such an instance, which is used for output produced by Typer, such as the help display. +The terminal width of this console can be forced using the environment variable `TERMINAL_WIDTH`. + +/// tip + +It is necessary to set these variables *before* importing a Typer app for testing. + +/// + ### Call `pytest` Then you can call `pytest` in your directory and it will run your tests: @@ -141,6 +159,7 @@ So, if you use `input="camila@example.com\n"` it means: "type `camila@example.co {* docs_src/testing/app02_py39/test_main.py hl[9] *} + ## Test a function If you have a script and you never created an explicit `typer.Typer` app, like: From 709d8548884965f800cb133f8ab68acf3e30b499 Mon Sep 17 00:00:00 2001 From: SyntacticSalt Date: Fri, 6 Feb 2026 14:28:10 +0100 Subject: [PATCH 2/2] Remove empty line --- docs/tutorial/testing.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/tutorial/testing.md b/docs/tutorial/testing.md index 911ec23afb..e701d9b6ed 100644 --- a/docs/tutorial/testing.md +++ b/docs/tutorial/testing.md @@ -159,7 +159,6 @@ So, if you use `input="camila@example.com\n"` it means: "type `camila@example.co {* docs_src/testing/app02_py39/test_main.py hl[9] *} - ## Test a function If you have a script and you never created an explicit `typer.Typer` app, like: