Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/tutorial/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

@svlandeg svlandeg Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a difference between the two though, TERMINAL_WIDTH needs to be defined even before importing typer. COLUMNS can be set at runtime. Perhaps it would make sense to provide an example in the line of #1542.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've clarified the tip to mention only TERMINAL_WIDTH.

I'm a bit confused about the PR you've linked; in my tests (and thats what started the discussion as well as this PR), COLUMNS has no effect on the output of a typer app with --help.
I'll test a bit more and add an example if i can reproduce the behavior of the linked PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you double check? Local tests went from failing to succeeding for both myself and the original poster of that PR, so I do think that including an example, maybe even just showing the code from test_tutorial/test_options/test_help/test_tutorial004.py, would be helpful.


///

### Call `pytest`

Then you can call `pytest` in your directory and it will run your tests:
Expand Down