Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r78219:fcb2ba48f07c Date: 2015-06-21 09:26 +0200 http://bitbucket.org/pypy/pypy/changeset/fcb2ba48f07c/
Log: Test and fix for a better error message on failing imports diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py --- a/rpython/flowspace/flowcontext.py +++ b/rpython/flowspace/flowcontext.py @@ -1207,7 +1207,8 @@ def nomoreblocks(self, ctx): w_exc = self.w_exc if w_exc.w_type == const(ImportError): - msg = 'import statement always raises %s' % self + msg = 'ImportError is raised in RPython: %s' % ( + getattr(w_exc.w_value, 'value', '<not a constant message>'),) raise ImportError(msg) link = Link([w_exc.w_type, w_exc.w_value], ctx.graph.exceptblock) ctx.recorder.crnt_block.closeblock(link) diff --git a/rpython/flowspace/test/cant_import.py b/rpython/flowspace/test/cant_import.py new file mode 100644 --- /dev/null +++ b/rpython/flowspace/test/cant_import.py @@ -0,0 +1,1 @@ +raise ImportError("some explanation here") diff --git a/rpython/flowspace/test/test_objspace.py b/rpython/flowspace/test/test_objspace.py --- a/rpython/flowspace/test/test_objspace.py +++ b/rpython/flowspace/test/test_objspace.py @@ -816,6 +816,12 @@ from rpython import this_does_not_exist py.test.raises(ImportError, 'self.codetest(f)') + def test_importerror_3(self): + def f(): + import rpython.flowspace.test.cant_import + e = py.test.raises(ImportError, 'self.codetest(f)') + assert "some explanation here" in str(e.value) + def test_relative_import(self): def f(): from ..objspace import build_flow _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit