Skip to content

Commit c04ef7a

Browse files
committed
Implement cli option.
1 parent cf478a7 commit c04ef7a

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/_pytask/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def main(config_from_cli: dict[str, Any]) -> Session:
126126
"[dim]\\[default: True][/]"
127127
),
128128
)
129+
@click.option("--dry-run", type=bool, is_flag=True, help="Perform a dry-run.")
129130
def build(**config_from_cli: Any) -> NoReturn:
130131
"""Collect tasks, execute them and report the results.
131132

src/_pytask/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ def pytask_parse_config(
246246
config_from_file.get("sort_table", True)
247247
)
248248

249+
config["dry_run"] = config_from_cli.get("dry_run", False)
250+
249251

250252
@hookimpl
251253
def pytask_post_parse(config: dict[str, Any]) -> None:

tests/test_execute.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,14 @@ def task_second(): pass
349349
assert ("Task task_example.py::task_second failed" in result.output) is (
350350
verbose == 2
351351
)
352+
353+
354+
@pytest.mark.end_to_end
355+
def test_dry_run(runner, tmp_path):
356+
tmp_path.joinpath("task_example.py").write_text("def task_example(): ...")
357+
358+
result = runner.invoke(cli, ["--dry-run", tmp_path.as_posix()])
359+
360+
print(result.output)
361+
assert result.exit_code == ExitCode.OK
362+
assert "1 Would be executed" in result.output

0 commit comments

Comments
 (0)