Skip to content

Commit 46925c2

Browse files
authored
Refactor test_worldclock to capture output correctly
1 parent e3f8b02 commit 46925c2

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

tests/test_worldclock.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,16 @@
4545
),
4646
],
4747
)
48-
def test_worldclock(monkeypatch, capsys, args, expected):
48+
def test_worldclock(monkeypatch, args, expected):
4949
mock_env = {
5050
"TIMEZONE_LIST": '["Europe/Berlin", "Australia/Sydney", "America/Los_Angeles"]'
5151
}
5252
monkeypatch.setattr(os, "environ", mock_env)
53-
worldclock.convert_time(*args)
54-
captured = capsys.readouterr()
55-
assert captured.out == expected
56-
53+
result = worldclock.convert_time(*args)
54+
output = "\n".join(
55+
f"{zone:25} {time}" for zone, time in result
56+
) + "\n"
57+
assert output == expected
5758

5859
def test_bad_timezone_json(monkeypatch, capsys):
5960
mock_env = {"TIMEZONE_LIST": '["CET" "Australia/Sydney", "America/Los_Angeles"]'}
@@ -123,11 +124,13 @@ def test_bad_timezone_entered(monkeypatch, capsys):
123124
),
124125
],
125126
)
126-
def test_worldclock_with_date_offset(monkeypatch, capsys, args, expected):
127+
def test_worldclock_with_date_offset(monkeypatch, args, expected):
127128
mock_env = {
128129
"TIMEZONE_LIST": '["Europe/Berlin", "Australia/Sydney", "America/Los_Angeles"]'
129130
}
130131
monkeypatch.setattr(os, "environ", mock_env)
131-
worldclock.convert_time(*args)
132-
captured = capsys.readouterr()
133-
assert captured.out == expected
132+
result = worldclock.convert_time(*args)
133+
output = "\n".join(
134+
f"{zone:25} {time}" for zone, time in result
135+
) + "\n"
136+
assert output == expected

0 commit comments

Comments
 (0)