diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index a8cac4b52d0..378b6ede3f5 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -536,9 +536,9 @@ def __init__( ) -> None: path, fspath = _imply_path(path, fspath=fspath) name = fspath.basename - if parent is not None: + if parent is not None and parent.path != path: try: - rel = Path(fspath).relative_to(parent.path) + rel = path.relative_to(parent.path) except ValueError: pass else: