MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_suppress_error_removing_lock

Function test_suppress_error_removing_lock

testing/test_pathlib.py:377–401  ·  view source on GitHub ↗

ensure_deletable should be resilient if lock file cannot be removed (#5456, #7491)

(tmp_path: Path)

Source from the content-addressed store, hash-verified

375
376
377def test_suppress_error_removing_lock(tmp_path: Path) -> None:
378 """ensure_deletable should be resilient if lock file cannot be removed (#5456, #7491)"""
379 path = tmp_path / "dir"
380 path.mkdir()
381 lock = get_lock_path(path)
382 lock.touch()
383 mtime = lock.stat().st_mtime
384
385 with unittest.mock.patch.object(Path, "unlink", side_effect=OSError) as m:
386 assert not ensure_deletable(
387 path, consider_lock_dead_if_created_before=mtime + 30
388 )
389 assert m.call_count == 1
390 assert lock.is_file()
391
392 with unittest.mock.patch.object(Path, "is_file", side_effect=OSError) as m:
393 assert not ensure_deletable(
394 path, consider_lock_dead_if_created_before=mtime + 30
395 )
396 assert m.call_count == 1
397 assert lock.is_file()
398
399 # check now that we can remove the lock file in normal circumstances
400 assert ensure_deletable(path, consider_lock_dead_if_created_before=mtime + 30)
401 assert not lock.is_file()
402
403
404def test_bestrelpath() -> None:

Callers

nothing calls this directly

Calls 3

get_lock_pathFunction · 0.90
ensure_deletableFunction · 0.90
mkdirMethod · 0.45

Tested by

no test coverage detected