|
11 | 11 | import pytest |
12 | 12 |
|
13 | 13 | import pytask |
| 14 | +from _pytask.mark import MARK_GEN |
14 | 15 | from pytask import CaptureMethod |
15 | 16 | from pytask import ExitCode |
16 | 17 | from pytask import NodeNotFoundError |
@@ -123,6 +124,45 @@ def task_3(paths = [Path("deleted.txt"), Path("out_2.txt")]): |
123 | 124 | assert isinstance(exc_info[1], NodeNotFoundError) |
124 | 125 |
|
125 | 126 |
|
| 127 | +@pytest.mark.parametrize("exit_code", [0, 7]) |
| 128 | +def test_system_exit_is_a_normal_task_failure(tmp_path, exit_code): |
| 129 | + source = f""" |
| 130 | + from pathlib import Path |
| 131 | +
|
| 132 | + def task_exits(produces=Path("upstream.txt")): |
| 133 | + raise SystemExit({exit_code}) |
| 134 | +
|
| 135 | + def task_descendant( |
| 136 | + path=Path("upstream.txt"), produces=Path("descendant.txt") |
| 137 | + ): |
| 138 | + produces.write_text(path.read_text()) |
| 139 | +
|
| 140 | + def task_unrelated(produces=Path("unrelated.txt")): |
| 141 | + produces.write_text("unrelated") |
| 142 | + """ |
| 143 | + tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source)) |
| 144 | + |
| 145 | + session = build(paths=tmp_path) |
| 146 | + |
| 147 | + assert session.exit_code == ExitCode.FAILED |
| 148 | + assert tmp_path.joinpath("unrelated.txt").read_text() == "unrelated" |
| 149 | + assert not tmp_path.joinpath("descendant.txt").exists() |
| 150 | + assert {report.outcome for report in session.execution_reports} == { |
| 151 | + TaskOutcome.FAIL, |
| 152 | + TaskOutcome.SKIP_PREVIOUS_FAILED, |
| 153 | + TaskOutcome.SUCCESS, |
| 154 | + } |
| 155 | + failed_report = next( |
| 156 | + report |
| 157 | + for report in session.execution_reports |
| 158 | + if report.outcome == TaskOutcome.FAIL |
| 159 | + ) |
| 160 | + assert failed_report.exc_info is not None |
| 161 | + assert isinstance(failed_report.exc_info[1], SystemExit) |
| 162 | + assert failed_report.exc_info[1].code == exit_code |
| 163 | + assert MARK_GEN.config is None |
| 164 | + |
| 165 | + |
126 | 166 | def test_depends_on_and_produces_can_be_used_in_task(tmp_path): |
127 | 167 | source = """ |
128 | 168 | from pathlib import Path |
|
0 commit comments