|
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 |
|
| 7 | +import _pytask.lockfile as lockfile_module |
7 | 8 | from _pytask.lockfile import LockfileError |
8 | 9 | from _pytask.lockfile import LockfileVersionError |
9 | 10 | from _pytask.lockfile import build_portable_node_id |
@@ -127,3 +128,33 @@ def func_second(path): |
127 | 128 | lockfile = read_lockfile(tmp_path / "pytask.lock") |
128 | 129 | assert lockfile is not None |
129 | 130 | assert {entry.id for entry in lockfile.task} == {"task_first"} |
| 131 | + |
| 132 | + |
| 133 | +def test_update_task_skips_write_when_unchanged(tmp_path, monkeypatch): |
| 134 | + def func(path): |
| 135 | + path.write_text("data") |
| 136 | + |
| 137 | + task = TaskWithoutPath( |
| 138 | + name="task", |
| 139 | + function=func, |
| 140 | + produces={"path": PathNode(path=tmp_path / "out.txt")}, |
| 141 | + ) |
| 142 | + |
| 143 | + session = build(tasks=[task], paths=tmp_path) |
| 144 | + assert session.exit_code == ExitCode.OK |
| 145 | + |
| 146 | + lockfile_state = session.config["lockfile_state"] |
| 147 | + assert lockfile_state is not None |
| 148 | + |
| 149 | + calls = {"count": 0} |
| 150 | + |
| 151 | + original_write = lockfile_module.write_lockfile |
| 152 | + |
| 153 | + def _counting_write(path, lockfile): |
| 154 | + calls["count"] += 1 |
| 155 | + return original_write(path, lockfile) |
| 156 | + |
| 157 | + monkeypatch.setattr(lockfile_module, "write_lockfile", _counting_write) |
| 158 | + lockfile_state.update_task(session, session.tasks[0]) |
| 159 | + |
| 160 | + assert calls["count"] == 0 |
0 commit comments