Display full traceback from Import errors when collecting test modules

Fix #1976
This commit is contained in:
Bruno Oliveira
2016-10-03 20:47:44 -03:00
parent fc02003220
commit 7d66e4eae1
6 changed files with 39 additions and 20 deletions

View File

@@ -424,12 +424,15 @@ class Module(pytest.File, PyCollector):
% e.args
)
except ImportError:
exc_class, exc, _ = sys.exc_info()
import traceback
stream = py.io.TextIO()
traceback.print_exc(file=stream)
formatted_tb = stream.getvalue()
raise self.CollectError(
"ImportError while importing test module '%s'.\n"
"Original error message:\n'%s'\n"
"Make sure your test modules/packages have valid Python names."
% (self.fspath, exc or exc_class)
"ImportError while importing test module '{fspath}'.\n"
"Hint: make sure your test modules/packages have valid Python names.\n"
"Original traceback:\n"
"{traceback}".format(fspath=self.fspath, traceback=formatted_tb)
)
except _pytest.runner.Skipped as e:
if e.allow_module_level: