diff --git a/src/_pytest/main.py b/src/_pytest/main.py index a6e860bb6..d8cd023cc 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -925,11 +925,12 @@ class Session(nodes.Collector): # In case the file paths do not match, fallback to samefile() to # account for short-paths on Windows (#11895). same_file = os.path.samefile(node.path, matchparts[0]) - # we don't want to find links, so we at least - # exclude symlinks to regular directories - is_match = same_file and os.path.islink( - node.path - ) == os.path.islink(matchparts[0]) + # We don't want to match links to the current node, + # otherwise we would match the same file more than once (#12039). + is_match = same_file and ( + os.path.islink(node.path) + == os.path.islink(matchparts[0]) + ) # Name part e.g. `TestIt` in `/a/b/test_file.py::TestIt::test_it`. else: