Skip to content

Output in stdout from the capsys fixture is different depending on whether or not -s is used #11203

Closed Answered by The-Compiler
dgard1981 asked this question in Q&A
Discussion options

You must be logged in to vote

This is unrelated to pytest - you'll see the same behaviour if you run Args.parse() with your code, and then look at the output of python3 script.py --help (output is a terminal) vs. python3 script.py --help | cat (output is not a terminal).

This is because argparse.HelpFormatter uses shutil.get_terminal_size() to get a wrapping width (if none is given), which then falls back to 80x24 when stdout is not a terminal:

When COLUMNS or LINES is not defined, which is the common case, the terminal connected to sys.__stdout__ is queried by invoking os.get_terminal_size().

If the terminal size cannot be successfully queried, either because the system doesn’t support querying, or because we are no…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dgard1981
Comment options

Answer selected by The-Compiler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants