2222 getlocation , enum ,
2323)
2424
25- cutdir2 = py .path .local (_pytest .__file__ ).dirpath ()
2625cutdir1 = py .path .local (pluggy .__file__ .rstrip ("oc" ))
26+ cutdir2 = py .path .local (_pytest .__file__ ).dirpath ()
27+ cutdir3 = py .path .local (py .__file__ ).dirpath ()
2728
2829
2930def filter_traceback (entry ):
31+ """Return True if a TracebackEntry instance should be removed from tracebacks:
32+ * dynamically generated code (no code to show up for it);
33+ * internal traceback from pytest or its internal libraries, py and pluggy.
34+ """
3035 # entry.path might sometimes return a str object when the entry
3136 # points to dynamically generated code
3237 # see https://bitbucket.org/pytest-dev/py/issues/71
@@ -37,7 +42,7 @@ def filter_traceback(entry):
3742 # entry.path might point to an inexisting file, in which case it will
3843 # alsso return a str object. see #1133
3944 p = py .path .local (entry .path )
40- return p != cutdir1 and not p .relto (cutdir2 )
45+ return p != cutdir1 and not p .relto (cutdir2 ) and not p . relto ( cutdir3 )
4146
4247
4348
@@ -424,12 +429,17 @@ def _importtestmodule(self):
424429 % e .args
425430 )
426431 except ImportError :
427- exc_class , exc , _ = sys .exc_info ()
432+ from _pytest ._code .code import ExceptionInfo
433+ exc_info = ExceptionInfo ()
434+ if self .config .getoption ('verbose' ) < 2 :
435+ exc_info .traceback = exc_info .traceback .filter (filter_traceback )
436+ exc_repr = exc_info .getrepr (style = 'short' ) if exc_info .traceback else exc_info .exconly ()
437+ formatted_tb = py ._builtin ._totext (exc_repr )
428438 raise self .CollectError (
429- "ImportError while importing test module '%s '.\n "
430- "Original error message: \n '%s' \n "
431- "Make sure your test modules/packages have valid Python names. "
432- % ( self .fspath , exc or exc_class )
439+ "ImportError while importing test module '{fspath} '.\n "
440+ "Hint: make sure your test modules/packages have valid Python names. \n "
441+ "Traceback: \n "
442+ "{traceback}" . format ( fspath = self .fspath , traceback = formatted_tb )
433443 )
434444 except _pytest .runner .Skipped as e :
435445 if e .allow_module_level :
0 commit comments