Skip to content

Commit beedab9

Browse files
committed
terminalprogress: disable when TERM=dumb
TERM=dumb shouldn't emit escape codes like terminalprogress does, it would likely come out as literal escape characters.
1 parent 6d6ae27 commit beedab9

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

changelog/13896.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
The terminal progress feature added in pytest 9.0.0 has been disabled by default, except on Windows, due to compatibility issues with some terminal emulators.
22

33
You may enable it again by passing ``-p terminalprogress``. We may enable it by default again once compatibility improves in the future.
4+
5+
Additionally, when the environment variable ``TERM`` is ``dumb``, the escape codes are no longer emitted, even if the plugin is enabled.

src/_pytest/terminalprogress.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
from __future__ import annotations
1313

14+
import os
15+
1416
from _pytest.config import Config
1517
from _pytest.config import hookimpl
1618
from _pytest.terminal import TerminalProgressPlugin
@@ -23,6 +25,6 @@ def pytest_configure(config: Config) -> None:
2325
"terminalreporter"
2426
)
2527

26-
if reporter is not None and reporter.isatty():
28+
if reporter is not None and reporter.isatty() and os.environ.get("TERM") != "dumb":
2729
plugin = TerminalProgressPlugin(reporter)
2830
config.pluginmanager.register(plugin, name="terminalprogress-plugin")

testing/test_terminal.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3460,6 +3460,16 @@ def test_disabled_for_non_tty(
34603460
plugin = config.pluginmanager.get_plugin("terminalprogress-plugin")
34613461
assert plugin is None
34623462

3463+
def test_disabled_for_dumb_terminal(
3464+
self, pytester: pytest.Pytester, monkeypatch: MonkeyPatch
3465+
) -> None:
3466+
"""Test that plugin is disabled when TERM=dumb."""
3467+
monkeypatch.setenv("TERM", "dumb")
3468+
monkeypatch.setattr(sys.stdout, "isatty", lambda: True)
3469+
config = pytester.parseconfigure("-p", "terminalprogress")
3470+
plugin = config.pluginmanager.get_plugin("terminalprogress-plugin")
3471+
assert plugin is None
3472+
34633473
@pytest.mark.parametrize(
34643474
["state", "progress", "expected"],
34653475
[

0 commit comments

Comments
 (0)