def test_do_not_collect_symlink_siblings(
    pytester: Pytester, tmp_path: Path, request: pytest.FixtureRequest
) -> None:
    """
    Regression test for #12039: Do not collect from directories that are symlinks to other directories in the same path.

    The check for short paths under Windows via os.path.samefile, introduced in #11936, also finds the symlinked
    directory created by tmp_path/tmpdir.
    """
    # Use tmp_path because it creates a symlink with the name "current" next to the directory it creates.
    symlink_path = tmp_path.parent / (tmp_path.name[:-1] + "current")
    assert symlink_path.is_symlink() is True

    # Create test file.
    tmp_path.joinpath("test_foo.py").write_text("def test(): pass", encoding="UTF-8")

    # Ensure we collect it only once if we pass the tmp_path.
    result = pytester.runpytest(tmp_path, "-sv")
    result.assert_outcomes(passed=1)

    # Ensure we collect it only once if we pass the symlinked directory.
    result = pytester.runpytest(symlink_path, "-sv")
    result.assert_outcomes(passed=1)

    Regression test for #12039: Do not collect from directories that are symlinks to other directories in the same path.

    The check for short paths under Windows via os.path.samefile, introduced in #11936, also finds the symlinked
    directory created by tmp_path/tmpdir.
    
testing/test_collection.py