MCPcopy
hub / github.com/pytest-dev/pytest / test_collect_sub_with_symlinks

Function test_collect_sub_with_symlinks

testing/test_collection.py:1530–1550  ·  view source on GitHub ↗

Collection works with symlinked files and broken symlinks

(use_pkg: bool, pytester: Pytester)

Source from the content-addressed store, hash-verified

1528
1529@pytest.mark.parametrize("use_pkg", (True, False))
1530def test_collect_sub_with_symlinks(use_pkg: bool, pytester: Pytester) -> None:
1531 """Collection works with symlinked files and broken symlinks"""
1532 sub = pytester.mkdir("sub")
1533 if use_pkg:
1534 sub.joinpath("__init__.py").touch()
1535 sub.joinpath("test_file.py").write_text("def test_file(): pass", encoding="utf-8")
1536
1537 # Create a broken symlink.
1538 symlink_or_skip("test_doesnotexist.py", sub.joinpath("test_broken.py"))
1539
1540 # Symlink that gets collected.
1541 symlink_or_skip("test_file.py", sub.joinpath("test_symlink.py"))
1542
1543 result = pytester.runpytest("-v", str(sub))
1544 result.stdout.fnmatch_lines(
1545 [
1546 "sub/test_file.py::test_file PASSED*",
1547 "sub/test_symlink.py::test_file PASSED*",
1548 "*2 passed in*",
1549 ]
1550 )
1551
1552
1553def test_collector_respects_tbstyle(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 5

symlink_or_skipFunction · 0.90
write_textMethod · 0.80
fnmatch_linesMethod · 0.80
mkdirMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected