4141from _pytest .compat import get_real_func
4242from _pytest .compat import overload
4343from _pytest .compat import TYPE_CHECKING
44+ from _pytest .pathlib import Path
4445
4546if TYPE_CHECKING :
4647 from typing import Type
@@ -1190,12 +1191,12 @@ def getfslineno(obj: object) -> Tuple[Union[str, py.path.local], int]:
11901191# note: if we need to add more paths than what we have now we should probably use a list
11911192# for better maintenance.
11921193
1193- _PLUGGY_DIR = py . path . local (pluggy .__file__ .rstrip ("oc" ))
1194+ _PLUGGY_DIR = Path (pluggy .__file__ .rstrip ("oc" ))
11941195# 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
11991200
12001201
12011202def filter_traceback (entry : TracebackEntry ) -> bool :
@@ -1213,9 +1214,17 @@ def filter_traceback(entry: TracebackEntry) -> bool:
12131214 is_generated = "<" in raw_filename and ">" in raw_filename
12141215 if is_generated :
12151216 return False
1217+
12161218 # entry.path might point to a non-existing file, in which case it will
12171219 # 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