22
22
getlocation , enum ,
23
23
)
24
24
25
- cutdir2 = py .path .local (_pytest .__file__ ).dirpath ()
26
25
cutdir1 = py .path .local (pluggy .__file__ .rstrip ("oc" ))
26
+ cutdir2 = py .path .local (_pytest .__file__ ).dirpath ()
27
+ cutdir3 = py .path .local (py .__file__ ).dirpath ()
27
28
28
29
29
30
def 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
+ """
30
35
# entry.path might sometimes return a str object when the entry
31
36
# points to dynamically generated code
32
37
# see https://bitbucket.org/pytest-dev/py/issues/71
@@ -37,7 +42,7 @@ def filter_traceback(entry):
37
42
# entry.path might point to an inexisting file, in which case it will
38
43
# alsso return a str object. see #1133
39
44
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 )
41
46
42
47
43
48
@@ -424,14 +429,16 @@ def _importtestmodule(self):
424
429
% e .args
425
430
)
426
431
except ImportError :
427
- import traceback
428
- stream = py .io .TextIO ()
429
- traceback .print_exc (file = stream )
430
- formatted_tb = stream .getvalue ()
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 )
431
438
raise self .CollectError (
432
439
"ImportError while importing test module '{fspath}'.\n "
433
440
"Hint: make sure your test modules/packages have valid Python names.\n "
434
- "Original traceback :\n "
441
+ "Traceback :\n "
435
442
"{traceback}" .format (fspath = self .fspath , traceback = formatted_tb )
436
443
)
437
444
except _pytest .runner .Skipped as e :
0 commit comments