Ejemplo n.º 1
0
def test_collect_sub_with_symlinks(use_pkg, testdir):
    """Collection works with symlinked files and broken symlinks"""
    sub = testdir.mkdir("sub")
    if use_pkg:
        sub.ensure("__init__.py")
    sub.join("test_file.py").write("def test_file(): pass")

    # Create a broken symlink.
    symlink_or_skip("test_doesnotexist.py", sub.join("test_broken.py"))

    # Symlink that gets collected.
    symlink_or_skip("test_file.py", sub.join("test_symlink.py"))

    result = testdir.runpytest("-v", str(sub))
    result.stdout.fnmatch_lines(
        [
            "sub/test_file.py::test_file PASSED*",
            "sub/test_symlink.py::test_file PASSED*",
            "*2 passed in*",
        ]
    )
Ejemplo n.º 2
0
def test_collect_symlink_out_of_tree(testdir):
    """Test collection of symlink via out-of-tree rootdir."""
    sub = testdir.tmpdir.join("sub")
    real = sub.join("test_real.py")
    real.write(
        textwrap.dedent("""
        def test_nodeid(request):
            # Should not contain sub/ prefix.
            assert request.node.nodeid == "test_real.py::test_nodeid"
        """),
        ensure=True,
    )

    out_of_tree = testdir.tmpdir.join("out_of_tree").ensure(dir=True)
    symlink_to_sub = out_of_tree.join("symlink_to_sub")
    symlink_or_skip(sub, symlink_to_sub)
    sub.chdir()
    result = testdir.runpytest("-vs", "--rootdir=%s" % sub, symlink_to_sub)
    result.stdout.fnmatch_lines([
        # Should not contain "sub/"!
        "test_real.py::test_nodeid PASSED"
    ])
    assert result.ret == 0