diff options
author | Armin Rigo <arigo@tunes.org> | 2015-06-21 09:26:29 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2015-06-21 09:26:29 +0200 |
commit | 5dd01a3df249bf368bca1862105395c198fed653 (patch) | |
tree | c24d7618e7d7b45858a7168678ba6cc851dc9dcf /rpython/flowspace | |
parent | Uh, this class is defined in this very file now. (diff) | |
download | pypy-5dd01a3df249bf368bca1862105395c198fed653.tar.gz pypy-5dd01a3df249bf368bca1862105395c198fed653.tar.bz2 pypy-5dd01a3df249bf368bca1862105395c198fed653.zip |
Test and fix for a better error message on failing imports
Diffstat (limited to 'rpython/flowspace')
-rw-r--r-- | rpython/flowspace/flowcontext.py | 3 | ||||
-rw-r--r-- | rpython/flowspace/test/cant_import.py | 1 | ||||
-rw-r--r-- | rpython/flowspace/test/test_objspace.py | 6 |
3 files changed, 9 insertions, 1 deletions
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py index 2144ba4a27..c204cb5f98 100644 --- a/rpython/flowspace/flowcontext.py +++ b/rpython/flowspace/flowcontext.py @@ -1207,7 +1207,8 @@ class Raise(FlowSignal): 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 index 0000000000..174bd09444 --- /dev/null +++ b/rpython/flowspace/test/cant_import.py @@ -0,0 +1 @@ +raise ImportError("some explanation here") diff --git a/rpython/flowspace/test/test_objspace.py b/rpython/flowspace/test/test_objspace.py index db4137d50d..37f8ef3d7e 100644 --- a/rpython/flowspace/test/test_objspace.py +++ b/rpython/flowspace/test/test_objspace.py @@ -816,6 +816,12 @@ class TestFlowObjSpace(Base): 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 |