41
41
from _pytest .compat import get_real_func
42
42
from _pytest .compat import overload
43
43
from _pytest .compat import TYPE_CHECKING
44
+ from _pytest .pathlib import Path
44
45
45
46
if TYPE_CHECKING :
46
47
from typing import Type
@@ -1190,12 +1191,12 @@ def getfslineno(obj: object) -> Tuple[Union[str, py.path.local], int]:
1190
1191
# note: if we need to add more paths than what we have now we should probably use a list
1191
1192
# for better maintenance.
1192
1193
1193
- _PLUGGY_DIR = py . path . local (pluggy .__file__ .rstrip ("oc" ))
1194
+ _PLUGGY_DIR = Path (pluggy .__file__ .rstrip ("oc" ))
1194
1195
# pluggy is either a package or a single module depending on the version
1195
- if _PLUGGY_DIR .basename == "__init__.py" :
1196
- _PLUGGY_DIR = _PLUGGY_DIR .dirpath ()
1197
- _PYTEST_DIR = py . path . local (_pytest .__file__ ).dirpath ()
1198
- _PY_DIR = py . path . local (py .__file__ ).dirpath ()
1196
+ if _PLUGGY_DIR .name == "__init__.py" :
1197
+ _PLUGGY_DIR = _PLUGGY_DIR .parent
1198
+ _PYTEST_DIR = Path (_pytest .__file__ ).parent
1199
+ _PY_DIR = Path (py .__file__ ).parent
1199
1200
1200
1201
1201
1202
def filter_traceback (entry : TracebackEntry ) -> bool :
@@ -1213,9 +1214,17 @@ def filter_traceback(entry: TracebackEntry) -> bool:
1213
1214
is_generated = "<" in raw_filename and ">" in raw_filename
1214
1215
if is_generated :
1215
1216
return False
1217
+
1216
1218
# entry.path might point to a non-existing file, in which case it will
1217
1219
# also return a str object. See #1133.
1218
- p = py .path .local (entry .path )
1219
- return (
1220
- not p .relto (_PLUGGY_DIR ) and not p .relto (_PYTEST_DIR ) and not p .relto (_PY_DIR )
1221
- )
1220
+ p = Path (entry .path )
1221
+
1222
+ parents = p .parents
1223
+ if _PLUGGY_DIR in parents :
1224
+ return False
1225
+ if _PYTEST_DIR in parents :
1226
+ return False
1227
+ if _PY_DIR in parents :
1228
+ return False
1229
+
1230
+ return True
0 commit comments