def test_collect_symlink_out_of_tree(pytester: Pytester) -> None:
    """Test collection of symlink via out-of-tree rootdir."""
    sub = pytester.mkdir("sub")
    real = sub.joinpath("test_real.py")
    real.write_text(
        textwrap.dedent(
            """
        def test_nodeid(request):
            # Should not contain sub/ prefix.
            assert request.node.nodeid == "test_real.py::test_nodeid"
        """
        ),
        encoding="utf-8",
    )

    out_of_tree = pytester.mkdir("out_of_tree")
    symlink_to_sub = out_of_tree.joinpath("symlink_to_sub")
    symlink_or_skip(sub, symlink_to_sub)
    os.chdir(sub)
    result = pytester.runpytest("-vs", f"--rootdir={sub}", symlink_to_sub)
    result.stdout.fnmatch_lines(
        [
            # Should not contain "sub/"!
            "test_real.py::test_nodeid PASSED"
        ]
    )
    assert result.ret == 0
Test collection of symlink via out-of-tree rootdir.
testing/test_collection.py