diff --git a/aiohttp/web.py b/aiohttp/web.py index 57858e49a42..1a5bf7ceffa 100644 --- a/aiohttp/web.py +++ b/aiohttp/web.py @@ -366,8 +366,8 @@ def main(argv): arg_parser.error("relative module names not supported") try: module = import_module(mod_str) - except ImportError: - arg_parser.error("module %r not found" % mod_str) + except ImportError as ex: + arg_parser.error("unable to import %s: %s" % (mod_str, ex)) try: func = getattr(module, func_str) except AttributeError: diff --git a/tests/test_web_cli.py b/tests/test_web_cli.py index e0331ae6335..850bcae0712 100644 --- a/tests/test_web_cli.py +++ b/tests/test_web_cli.py @@ -69,14 +69,15 @@ def test_entry_func_relative_module(mocker): def test_entry_func_non_existent_module(mocker): argv = ["alpha.beta:func"] - mocker.patch("aiohttp.web.import_module", side_effect=ImportError) + mocker.patch("aiohttp.web.import_module", + side_effect=ImportError("Test Error")) error = mocker.patch("aiohttp.web.ArgumentParser.error", side_effect=SystemExit) with pytest.raises(SystemExit): web.main(argv) - error.assert_called_with("module %r not found" % "alpha.beta") + error.assert_called_with('unable to import alpha.beta: Test Error') def test_entry_func_non_existent_attribute(mocker):