File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,9 @@ development at the same time, such as 4.5.x and 5.0.
2020 Unreleased
2121----------
2222
23- Nothing yet.
23+ - Fix: ``html_report() `` could fail with an AttributeError on ``isatty `` if run
24+ in an unusual environment where sys.stdout had been replaced. This is now
25+ fixed.
2426
2527
2628.. scriv-start-here
Original file line number Diff line number Diff line change @@ -394,7 +394,7 @@ def stdout_link(text: str, url: str) -> str:
394394 If attached to a terminal, use escape sequences. Otherwise, just return
395395 the text.
396396 """
397- if sys .stdout .isatty ():
397+ if hasattr ( sys . stdout , "isatty" ) and sys .stdout .isatty ():
398398 return f"\033 ]8;;{ url } \a { text } \033 ]8;;\a "
399399 else :
400400 return text
Original file line number Diff line number Diff line change 66from __future__ import annotations
77
88import sys
9+ from typing import Any
910from unittest import mock
1011
1112import pytest
@@ -165,3 +166,19 @@ def test_stdout_link_tty() -> None:
165166def test_stdout_link_not_tty () -> None :
166167 # Without mocking isatty, it reports False in a pytest suite.
167168 assert stdout_link ("some text" , "some url" ) == "some text"
169+
170+
171+ def test_stdout_link_with_fake_stdout () -> None :
172+ # If stdout is another object, we should still be ok.
173+ class FakeStdout :
174+ """New stdout, has .write(), but not .isatty()."""
175+ def __init__ (self , f : Any ) -> None :
176+ self .f = f
177+
178+ def write (self , data : str ) -> Any :
179+ """Write through to the underlying file."""
180+ return self .f .write (data )
181+
182+ with mock .patch .object (sys , "stdout" , FakeStdout (sys .stdout )):
183+ link = stdout_link ("some text" , "some url" )
184+ assert link == "some text"
You can’t perform that action at this time.
0 commit comments