Skip to content

Commit 434d30d

Browse files
committed
refactor(tests): convert test_util.py TTY test to use NamedTuple fixtures
1 parent 5fbc021 commit 434d30d

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

tests/test_util.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,38 @@ def temp_script(tmp_path: pathlib.Path) -> pathlib.Path:
5151
return script
5252

5353

54+
class TTYTestFixture(t.NamedTuple):
55+
"""Test fixture for isatty behavior verification."""
56+
57+
test_id: str
58+
isatty_value: bool
59+
expected_output: str
60+
61+
62+
TTY_TEST_FIXTURES: list[TTYTestFixture] = [
63+
TTYTestFixture(
64+
test_id="tty_enabled_shows_output",
65+
isatty_value=True,
66+
expected_output="Hello, World!",
67+
),
68+
TTYTestFixture(
69+
test_id="tty_disabled_suppresses_output",
70+
isatty_value=False,
71+
expected_output="",
72+
),
73+
]
74+
75+
5476
@pytest.mark.parametrize(
55-
["isatty_value", "expected_output"],
56-
[
57-
(True, "Hello, World!"), # if stdout is a TTY, output should be passed through
58-
(False, ""), # if not a TTY, output is not written to sys.stdout
59-
],
77+
list(TTYTestFixture._fields),
78+
TTY_TEST_FIXTURES,
79+
ids=[test.test_id for test in TTY_TEST_FIXTURES],
6080
)
6181
def test_run_before_script_isatty(
6282
temp_script: pathlib.Path,
6383
monkeypatch: pytest.MonkeyPatch,
6484
capsys: pytest.CaptureFixture[str],
85+
test_id: str,
6586
isatty_value: bool,
6687
expected_output: str,
6788
) -> None:

0 commit comments

Comments
 (0)