Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show more verbose message on import errors #1319

Merged
merged 1 commit into from
Oct 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_web_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down