30
30
from _pytest .outcomes import fail
31
31
from _pytest .mark import transfer_markers
32
32
33
- cutdir1 = py .path .local (pluggy .__file__ .rstrip ("oc" ))
34
- cutdir2 = py .path .local (_pytest .__file__ ).dirpath ()
35
- cutdir3 = py .path .local (py .__file__ ).dirpath ()
33
+
34
+ # relative paths that we use to filter traceback entries from appearing to the user;
35
+ # see filter_traceback
36
+ # note: if we need to add more paths than what we have now we should probably use a list
37
+ # for better maintenance
38
+ _pluggy_dir = py .path .local (pluggy .__file__ .rstrip ("oc" ))
39
+ # pluggy is either a package or a single module depending on the version
40
+ if _pluggy_dir .basename == '__init__.py' :
41
+ _pluggy_dir = _pluggy_dir .dirpath ()
42
+ _pytest_dir = py .path .local (_pytest .__file__ ).dirpath ()
43
+ _py_dir = py .path .local (py .__file__ ).dirpath ()
36
44
37
45
38
46
def filter_traceback (entry ):
@@ -47,10 +55,10 @@ def filter_traceback(entry):
47
55
is_generated = '<' in raw_filename and '>' in raw_filename
48
56
if is_generated :
49
57
return False
50
- # entry.path might point to an inexisting file, in which case it will
51
- # alsso return a str object. see #1133
58
+ # entry.path might point to an non-existing file, in which case it will
59
+ # also return a str object. see #1133
52
60
p = py .path .local (entry .path )
53
- return p != cutdir1 and not p .relto (cutdir2 ) and not p .relto (cutdir3 )
61
+ return not p . relto ( _pluggy_dir ) and not p .relto (_pytest_dir ) and not p .relto (_py_dir )
54
62
55
63
56
64
def pyobj_property (name ):
@@ -563,7 +571,6 @@ def _prunetraceback(self, excinfo):
563
571
if ntraceback == traceback :
564
572
ntraceback = ntraceback .cut (path = path )
565
573
if ntraceback == traceback :
566
- # ntraceback = ntraceback.cut(excludepath=cutdir2)
567
574
ntraceback = ntraceback .filter (filter_traceback )
568
575
if not ntraceback :
569
576
ntraceback = traceback
0 commit comments