diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2023-04-30 06:28:24 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2023-04-30 06:28:24 -0400 |
commit | 731e9a776539dde46ca4c626ed67a5a09e0fe76a (patch) | |
tree | 0bff422471183aafd12c6da0135642c1ecf10765 /tests | |
parent | 31c216b67ffb21c589fd39b55fe1bbd26d5bf705 (diff) | |
download | python-coveragepy-git-731e9a776539dde46ca4c626ed67a5a09e0fe76a.tar.gz |
fix: a fake stdout might not have isatty
Diffstat (limited to 'tests')
-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" |