diff options
Diffstat (limited to 'tests/test_misc.py')
-rw-r--r-- | tests/test_misc.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/test_misc.py b/tests/test_misc.py index 455a3bc1..d489f171 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -6,6 +6,7 @@ from __future__ import annotations import sys +from typing import Any from unittest import mock import pytest @@ -165,3 +166,19 @@ def test_stdout_link_tty() -> None: def test_stdout_link_not_tty() -> None: # Without mocking isatty, it reports False in a pytest suite. assert stdout_link("some text", "some url") == "some text" + + +def test_stdout_link_with_fake_stdout() -> None: + # If stdout is another object, we should still be ok. + class FakeStdout: + """New stdout, has .write(), but not .isatty().""" + def __init__(self, f: Any) -> None: + self.f = f + + def write(self, data: str) -> Any: + """Write through to the underlying file.""" + return self.f.write(data) + + with mock.patch.object(sys, "stdout", FakeStdout(sys.stdout)): + link = stdout_link("some text", "some url") + assert link == "some text" |