From 062a0e3e68fef4f6c927442daf35a3e47e72cd8a Mon Sep 17 00:00:00 2001 From: Ofir Date: Tue, 19 Sep 2017 15:14:08 +0300 Subject: [PATCH] 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. --- _pytest/config.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/_pytest/config.py b/_pytest/config.py index 690f98587..595bebe35 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -423,12 +423,12 @@ class PytestPluginManager(PluginManager): try: __import__(importspec) except ImportError as e: - new_exc = ImportError('Error importing plugin "%s": %s' % (modname, safe_str(e.args[0]))) - # copy over name and path attributes - for attr in ('name', 'path'): - if hasattr(e, attr): - setattr(new_exc, attr, getattr(e, attr)) - raise new_exc + new_exc_type = ImportError + new_exc_message = 'Error importing plugin "%s": %s' % (modname, safe_str(e.args[0])) + new_exc = new_exc_type(new_exc_message) + + six.reraise(new_exc_type, new_exc, sys.exc_info()[2]) + except Exception as e: import pytest if not hasattr(pytest, 'skip') or not isinstance(e, pytest.skip.Exception):