Skip to content

Commit 307ca26

Browse files
committed
Use caplog fixure rather than mock logging when testing HTEX shutdown
This replaces mock-captured call sequences which are over-testing the exact position of tested log calls in relation to any other log calls, which makes this test fragile when working on logs in the affected area of the code. This is consistent with other parts of the test suite which test log messages using caplog.
1 parent 9c982c5 commit 307ca26

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

parsl/tests/test_htex/test_htex.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ def test_htex_start_encrypted(
7171
@pytest.mark.local
7272
@pytest.mark.parametrize("started", (True, False))
7373
@pytest.mark.parametrize("timeout_expires", (True, False))
74-
@mock.patch(f"{_MOCK_BASE}.logger")
7574
def test_htex_shutdown(
76-
mock_logger: mock.MagicMock,
7775
started: bool,
7876
timeout_expires: bool,
7977
htex: HighThroughputExecutor,
78+
caplog
8079
):
8180
mock_ix_proc = mock.Mock(spec=Popen)
8281

@@ -110,20 +109,19 @@ def kill_interchange(*args, **kwargs):
110109

111110
htex.shutdown()
112111

113-
mock_logs = mock_logger.info.call_args_list
114112
if started:
115113
assert mock_ix_proc.terminate.called
116114
assert mock_ix_proc.wait.called
117115
assert {"timeout": 10} == mock_ix_proc.wait.call_args[1]
118116
if timeout_expires:
119-
assert "Unable to terminate Interchange" in mock_logs[1][0][0]
117+
assert "Unable to terminate Interchange" in caplog.text
120118
assert mock_ix_proc.kill.called
121-
assert "Attempting" in mock_logs[0][0][0]
122-
assert "Finished" in mock_logs[-1][0][0]
119+
assert "Attempting HighThroughputExecutor shutdown" in caplog.text
120+
assert "Finished HighThroughputExecutor shutdown" in caplog.text
123121
else:
124122
assert not mock_ix_proc.terminate.called
125123
assert not mock_ix_proc.wait.called
126-
assert "has not started" in mock_logs[0][0][0]
124+
assert "HighThroughputExecutor has not started" in caplog.text
127125

128126

129127
@pytest.mark.local

0 commit comments

Comments
 (0)