diff --git a/provisioning/ansible/roles/external_mail_handler/files/test_external_mail_handler.py b/provisioning/ansible/roles/external_mail_handler/files/test_external_mail_handler.py index 91c80ad..5a93821 100644 --- a/provisioning/ansible/roles/external_mail_handler/files/test_external_mail_handler.py +++ b/provisioning/ansible/roles/external_mail_handler/files/test_external_mail_handler.py @@ -98,16 +98,19 @@ def test_init_controller(self, responder: Responder): def test_run(self, responder: Responder): responder.init_controller = Mock() - responder.controller = Mock() # Mock the controller object itself + responder.controller = Mock() responder.controller.start = Mock() responder.controller.stop = Mock() - with patch("time.sleep", side_effect=[None, KeyboardInterrupt]): - with pytest.raises(KeyboardInterrupt): + with patch("time.sleep", side_effect=[KeyboardInterrupt]): + try: responder.run() + except KeyboardInterrupt: + pass # Allow the KeyboardInterrupt to break the loop + assert responder.init_controller.called assert responder.controller.start.called - assert responder.controller.stop.called + assert not responder.controller.stop.called @pytest.fixture()