test_run: Patch importlib.import_module last.

importlib.import_module is now used in the implementation of
unittest.mock.patch.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-25 14:59:31 -07:00
parent 6b585f8b73
commit 183bb933b4

View file

@ -120,11 +120,11 @@ class TestDefaultArguments(TestCase):
with patch(
"sys.argv", ["zulip-run-bot", "bot.module.name", "--config-file", "/path/to/config"]
):
with patch(
"importlib.import_module", return_value=mock_bot_module
) as mock_import_module:
with patch("zulip_bots.run.run_message_handler_for_bot"):
with patch("zulip_bots.run.exit_gracefully_if_zulip_config_is_missing"):
with patch("zulip_bots.run.run_message_handler_for_bot"):
with patch("zulip_bots.run.exit_gracefully_if_zulip_config_is_missing"):
with patch(
"importlib.import_module", return_value=mock_bot_module
) as mock_import_module:
zulip_bots.run.main()
mock_import_module.assert_called_once_with(bot_module_name)