Skip to content

Commit 5ac4a0c

Browse files
committed
refactor(tests): convert test_util.py TTY test to use NamedTuple fixtures
1 parent 0b92354 commit 5ac4a0c

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
@@ -18,6 +18,28 @@
1818
from libtmux.server import Server
1919

2020

21+
class TTYTestFixture(t.NamedTuple):
22+
"""Test fixture for isatty behavior verification."""
23+
24+
test_id: str
25+
isatty_value: bool
26+
expected_output: str
27+
28+
29+
TTY_TEST_FIXTURES: list[TTYTestFixture] = [
30+
TTYTestFixture(
31+
test_id="tty_enabled_shows_output",
32+
isatty_value=True,
33+
expected_output="Hello, World!",
34+
),
35+
TTYTestFixture(
36+
test_id="tty_disabled_suppresses_output",
37+
isatty_value=False,
38+
expected_output="",
39+
),
40+
]
41+
42+
2143
def test_run_before_script_raise_BeforeLoadScriptNotExists_if_not_exists() -> None:
2244
"""run_before_script() raises BeforeLoadScriptNotExists if script not found."""
2345
script_file = FIXTURE_PATH / "script_noexists.sh"
@@ -52,16 +74,15 @@ def temp_script(tmp_path: pathlib.Path) -> pathlib.Path:
5274

5375

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)