File tree 3 files changed +21
-2
lines changed
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.
20
20
Unreleased
21
21
----------
22
22
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.
24
26
25
27
26
28
.. 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:
394
394
If attached to a terminal, use escape sequences. Otherwise, just return
395
395
the text.
396
396
"""
397
- if sys .stdout .isatty ():
397
+ if hasattr ( sys . stdout , "isatty" ) and sys .stdout .isatty ():
398
398
return f"\033 ]8;;{ url } \a { text } \033 ]8;;\a "
399
399
else :
400
400
return text
Original file line number Diff line number Diff line change 6
6
from __future__ import annotations
7
7
8
8
import sys
9
+ from typing import Any
9
10
from unittest import mock
10
11
11
12
import pytest
@@ -165,3 +166,19 @@ def test_stdout_link_tty() -> None:
165
166
def test_stdout_link_not_tty () -> None :
166
167
# Without mocking isatty, it reports False in a pytest suite.
167
168
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