| 57 | real_open = os.open |
| 58 | |
| 59 | def deny_write(path: str, flags: int, mode: int = 0o777, *, dir_fd: int | None = None) -> int: |
| 60 | if not flags & os.O_CREAT and str(tmp_path / "test.lock") == path: |
| 61 | if flags & os.O_RDWR: |
| 62 | if behavior == "unlink": |
| 63 | (tmp_path / "test.lock").unlink() |
| 64 | raise PermissionError(EACCES, "Permission denied", path) |
| 65 | if behavior == "leased": |
| 66 | raise BlockingIOError(EWOULDBLOCK, "Resource temporarily unavailable", path) |
| 67 | return real_open(path, flags, mode, dir_fd=dir_fd) |
| 68 | |
| 69 | mocker.patch("os.open", side_effect=deny_write, autospec=True) |
| 70 | |