Skip to content

Add environment variable check to force console output - #145

Open
timwoj wants to merge 1 commit into
masterfrom
topic/timw/143-windows-output-counting
Open

timwoj wants to merge 1 commit into
masterfrom
topic/timw/143-windows-output-counting

Conversation

@timwoj

@timwoj timwoj commented Sep 9, 2026

Copy link
Copy Markdown
Member

Taken from @awelzel's suggestion in #143 (comment).

Fixes #143

@timwoj
timwoj requested a review from bbannier September 15, 2026 01:01
Comment thread btest

else:
if sys.stdout.isatty():
if sys.stdout.isatty() or os.getenv("BTEST_FORCE_CONSOLE_OUTPUT", "0") == "1":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

WDYT about adding a proper option for this, and also reading a default from the environment like we do for --progress-bar?

btest/btest

Lines 3026 to 3033 in 1e97bbe

optparser.add_option(
"-P",
"--progress-bar",
action="store_true",
dest="osc94_progress",
default=os.environ.get("BTEST_OSC94_PROGRESS", ""),
help="display progress bar using OSC 9;4 escape sequences (set BTEST_OSC94_PROGRESS to permanently enable)",
)

It would also be nice to add a test for this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree — my suggestion would be to expand this PR a little bit. How about:

  • add --tty to force console use
  • use BTEST_FORCE_TTY as the corresponding variable
  • wrap sys.stdout.isatty() or os.getenv("BTEST_FORCE_TTY") into a helper and use that instead of sys.stdout.isatty(). We have multiple of these and I'm not sure e.g. --progress works reliably in that Windows setting either.

If you have it in you it would also be handy to get a summary of supported BTEST_* env vars in the help output. I just had to remind myself and there are more than I would have come up with. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows output displays differently than other platforms

3 participants