Skip to content
Open
Changes from all 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
30 changes: 30 additions & 0 deletions docs/tutorial/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,36 @@ 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.

/// tip

To avoid polluting the environment outside of the current test run, use monkeypatch to set the environment variable:

```Python
@pytest.fixture()
def console_width(monkeypatch):
monkeypatch.setenv("COLUMNS", "200")
```

///

/// tip

Typer also creates such an instance, which is used for output produced by Typer, such as the help display.
If you only want to modify the output width of this internal usage, you can set the environment variable `TERMINAL_WIDTH`.

It is necessary to set `TERMINAL_WIDTH` *before* the Typer app is imported.

///

### Call `pytest`

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