Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog/13896.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +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.
12 changes: 10 additions & 2 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import datetime
from functools import partial
import inspect
import os
from pathlib import Path
import platform
import sys
Expand Down Expand Up @@ -299,8 +300,15 @@ def mywriter(tags, args):
config.trace.root.setprocessor("pytest:config", mywriter)

if reporter.isatty():
plugin = TerminalProgressPlugin(reporter)
config.pluginmanager.register(plugin, "terminalprogress")
# Some terminals interpret OSC 9;4 as desktop notification,
# skip on those we know (#13896).
should_skip_terminal_progress = (
# iTerm2 (reported on version 3.6.5).
"ITERM_SESSION_ID" in os.environ
)
if not should_skip_terminal_progress:
plugin = TerminalProgressPlugin(reporter)
config.pluginmanager.register(plugin, "terminalprogress")
Comment on lines 302 to +311
Copy link
Member

Choose a reason for hiding this comment

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

This feels overly nested. How about

Suggested change
if reporter.isatty():
plugin = TerminalProgressPlugin(reporter)
config.pluginmanager.register(plugin, "terminalprogress")
# Some terminals interpret OSC 9;4 as desktop notification,
# skip on those we know (#13896).
should_skip_terminal_progress = (
# iTerm2 (reported on version 3.6.5).
"ITERM_SESSION_ID" in os.environ
)
if not should_skip_terminal_progress:
plugin = TerminalProgressPlugin(reporter)
config.pluginmanager.register(plugin, "terminalprogress")
# Some terminals interpret OSC 9;4 as desktop notification,
# skip on those we know (#13896).
should_skip_terminal_progress = (
# iTerm2 (reported on version 3.6.5).
"ITERM_SESSION_ID" in os.environ
) or not reporter.isatty()
if should_skip_terminal_progress:
return
plugin = TerminalProgressPlugin(reporter)
config.pluginmanager.register(plugin, "terminalprogress")

?

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer to avoid early return in hooks because it's possible we add more unrelated stuff to it in the future.

Copy link
Member

Choose a reason for hiding this comment

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

So

Suggested change
if reporter.isatty():
plugin = TerminalProgressPlugin(reporter)
config.pluginmanager.register(plugin, "terminalprogress")
# Some terminals interpret OSC 9;4 as desktop notification,
# skip on those we know (#13896).
should_skip_terminal_progress = (
# iTerm2 (reported on version 3.6.5).
"ITERM_SESSION_ID" in os.environ
)
if not should_skip_terminal_progress:
plugin = TerminalProgressPlugin(reporter)
config.pluginmanager.register(plugin, "terminalprogress")
# Some terminals interpret OSC 9;4 as desktop notification,
# skip on those we know (#13896).
enable_terminal_progress = (
# iTerm2 (reported on version 3.6.5).
"ITERM_SESSION_ID" not in os.environ
) and reporter.isatty()
if enable_terminal_progress:
plugin = TerminalProgressPlugin(reporter)
config.pluginmanager.register(plugin, "terminalprogress")

then?

Copy link
Member Author

Choose a reason for hiding this comment

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

It messes with the comment a bit. The isatty is the more important check, but I want to have a dedicated comment for the entire "unsupported terminals" check (in case we decide to add more cases).



def getreportopt(config: Config) -> str:
Expand Down
11 changes: 11 additions & 0 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3443,6 +3443,17 @@ def test_disabled_for_non_tty(self, pytester: pytest.Pytester) -> None:
plugin = config.pluginmanager.get_plugin("terminalprogress")
assert plugin is None

def test_disabled_for_iterm2(self, pytester: pytest.Pytester, monkeypatch) -> None:
"""Should not register the plugin on iTerm2 terminal since it interprets
OSC 9;4 as desktop notifications, not progress (#13896)."""
monkeypatch.setenv(
"ITERM_SESSION_ID", "w0t1p0:3DB6DF06-FE11-40C3-9A66-9E10A193A632"
)
with patch.object(sys.stdout, "isatty", return_value=True):
config = pytester.parseconfigure()
plugin = config.pluginmanager.get_plugin("terminalprogress")
assert plugin is None

@pytest.mark.parametrize(
["state", "progress", "expected"],
[
Expand Down