From 3ea987ef9d1650a1af681ba3b809109c4188a0c9 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 10 Mar 2016 18:13:59 -0300 Subject: [PATCH] Copy over name and path attributes to the re-raised exception --- _pytest/config.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/_pytest/config.py b/_pytest/config.py index ed5138cf4..fb7b1774f 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -384,7 +384,12 @@ class PytestPluginManager(PluginManager): try: __import__(importspec) except ImportError as e: - raise ImportError('Error importing plugin "%s": %s' % (modname, e)) + new_exc = ImportError('Error importing plugin "%s": %s' % (modname, e)) + # 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 except Exception as e: import pytest if not hasattr(pytest, 'skip') or not isinstance(e, pytest.skip.Exception):