Skip to content

Commit f2316b3

Browse files
committed
terminal: disable terminal progress plugin on iTerm2
Fix #13896
1 parent 4253f98 commit f2316b3

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

changelog/13896.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The terminal progress plugin added in pytest 9.0 is now automatically disabled when iTerm2 is detected, it generated desktop notifications instead of the desired functionality.

src/_pytest/terminal.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import datetime
1717
from functools import partial
1818
import inspect
19+
import os
1920
from pathlib import Path
2021
import platform
2122
import sys
@@ -299,8 +300,15 @@ def mywriter(tags, args):
299300
config.trace.root.setprocessor("pytest:config", mywriter)
300301

301302
if reporter.isatty():
302-
plugin = TerminalProgressPlugin(reporter)
303-
config.pluginmanager.register(plugin, "terminalprogress")
303+
# Some terminals interpret OSC 9;4 as desktop notification,
304+
# skip on those we know (#13896).
305+
should_skip_terminal_progress = (
306+
# iTerm2 (reported on version 3.6.5).
307+
"ITERM_SESSION_ID" in os.environ
308+
)
309+
if not should_skip_terminal_progress:
310+
plugin = TerminalProgressPlugin(reporter)
311+
config.pluginmanager.register(plugin, "terminalprogress")
304312

305313

306314
def getreportopt(config: Config) -> str:

testing/test_terminal.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,6 +3443,17 @@ def test_disabled_for_non_tty(self, pytester: pytest.Pytester) -> None:
34433443
plugin = config.pluginmanager.get_plugin("terminalprogress")
34443444
assert plugin is None
34453445

3446+
def test_disabled_for_iterm2(self, pytester: pytest.Pytester, monkeypatch) -> None:
3447+
"""Should not register the plugin on iTerm2 terminal since it interprets
3448+
OSC 9;4 as desktop notifications, not progress (#13896)."""
3449+
monkeypatch.setenv(
3450+
"ITERM_SESSION_ID", "w0t1p0:3DB6DF06-FE11-40C3-9A66-9E10A193A632"
3451+
)
3452+
with patch.object(sys.stdout, "isatty", return_value=True):
3453+
config = pytester.parseconfigure()
3454+
plugin = config.pluginmanager.get_plugin("terminalprogress")
3455+
assert plugin is None
3456+
34463457
@pytest.mark.parametrize(
34473458
["state", "progress", "expected"],
34483459
[

0 commit comments

Comments
 (0)