Merge pull request #2791 from OfirOshir/features
bugfix for issue #2491
This commit is contained in:
commit
f743e95cfc
|
@ -423,12 +423,12 @@ class PytestPluginManager(PluginManager):
|
||||||
try:
|
try:
|
||||||
__import__(importspec)
|
__import__(importspec)
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
new_exc = ImportError('Error importing plugin "%s": %s' % (modname, safe_str(e.args[0])))
|
new_exc_type = ImportError
|
||||||
# copy over name and path attributes
|
new_exc_message = 'Error importing plugin "%s": %s' % (modname, safe_str(e.args[0]))
|
||||||
for attr in ('name', 'path'):
|
new_exc = new_exc_type(new_exc_message)
|
||||||
if hasattr(e, attr):
|
|
||||||
setattr(new_exc, attr, getattr(e, attr))
|
six.reraise(new_exc_type, new_exc, sys.exc_info()[2])
|
||||||
raise new_exc
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import pytest
|
import pytest
|
||||||
if not hasattr(pytest, 'skip') or not isinstance(e, pytest.skip.Exception):
|
if not hasattr(pytest, 'skip') or not isinstance(e, pytest.skip.Exception):
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
If an exception happens while loading a plugin, pytest no longer hides the original traceback.
|
||||||
|
In python2 it will show the original traceback with a new message that explains in which plugin.
|
||||||
|
In python3 it will show 2 canonized exceptions, the original exception while loading the plugin
|
||||||
|
in addition to an exception that PyTest throws about loading a plugin.
|
|
@ -199,12 +199,17 @@ def test_importplugin_error_message(testdir, pytestpm):
|
||||||
testdir.syspathinsert(testdir.tmpdir)
|
testdir.syspathinsert(testdir.tmpdir)
|
||||||
testdir.makepyfile(qwe="""
|
testdir.makepyfile(qwe="""
|
||||||
# encoding: UTF-8
|
# encoding: UTF-8
|
||||||
raise ImportError(u'Not possible to import: ☺')
|
def test_traceback():
|
||||||
|
raise ImportError(u'Not possible to import: ☺')
|
||||||
|
test_traceback()
|
||||||
""")
|
""")
|
||||||
with pytest.raises(ImportError) as excinfo:
|
with pytest.raises(ImportError) as excinfo:
|
||||||
pytestpm.import_plugin("qwe")
|
pytestpm.import_plugin("qwe")
|
||||||
expected = '.*Error importing plugin "qwe": Not possible to import: .'
|
|
||||||
assert py.std.re.match(expected, str(excinfo.value))
|
expected_message = '.*Error importing plugin "qwe": Not possible to import: .'
|
||||||
|
expected_traceback = ".*in test_traceback"
|
||||||
|
assert py.std.re.match(expected_message, str(excinfo.value))
|
||||||
|
assert py.std.re.match(expected_traceback, str(excinfo.traceback[-1]))
|
||||||
|
|
||||||
|
|
||||||
class TestPytestPluginManager(object):
|
class TestPytestPluginManager(object):
|
||||||
|
|
Loading…
Reference in New Issue