|
39 | 39 | from _pytest.pathlib import resolve_pkg_root_and_module_name |
40 | 40 | from _pytest.pathlib import safe_exists |
41 | 41 | from _pytest.pathlib import scandir |
| 42 | +from _pytest.pathlib import samefile_nofollow |
42 | 43 | from _pytest.pathlib import spec_matches_module_path |
43 | 44 | from _pytest.pathlib import symlink_or_skip |
44 | 45 | from _pytest.pathlib import visit |
@@ -570,6 +571,20 @@ def test_samefile_false_negatives(tmp_path: Path, monkeypatch: MonkeyPatch) -> N |
570 | 571 | assert getattr(module, "foo")() == 42 |
571 | 572 |
|
572 | 573 |
|
| 574 | +@pytest.mark.parametrize("inodes", [(0, 0), (0, 1), (1, 0)]) |
| 575 | +def test_samefile_nofollow_rejects_zero_inodes( |
| 576 | + inodes: tuple[int, int], monkeypatch: MonkeyPatch |
| 577 | +) -> None: |
| 578 | + stats = [unittest.mock.Mock(st_ino=inode) for inode in inodes] |
| 579 | + lstat = unittest.mock.Mock(side_effect=stats) |
| 580 | + samestat = unittest.mock.Mock(return_value=True) |
| 581 | + monkeypatch.setattr(Path, "lstat", lstat) |
| 582 | + monkeypatch.setattr(os.path, "samestat", samestat) |
| 583 | + |
| 584 | + assert not samefile_nofollow(Path("first"), Path("second")) |
| 585 | + samestat.assert_not_called() |
| 586 | + |
| 587 | + |
573 | 588 | def test_scandir_with_non_existent_directory() -> None: |
574 | 589 | # Test with a directory that does not exist |
575 | 590 | non_existent_dir = "path_to_non_existent_dir" |
|
0 commit comments