Skip to content

Commit 2eb480e

Browse files
authored
Give skips higher precendence than ancestor failed as outcome. (#479)
1 parent c3dd1db commit 2eb480e

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

docs/source/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
2525
- {pull}`473` adds signatures to nodes which decouples an identifier from a name.
2626
- {pull}`477` updates the PyPI action.
2727
- {pull}`478` replaces black with ruff-format.
28+
- {pull}`479` gives skips a higher precedence as an outcome than ancestor failed.
2829

2930
## 0.4.1 - 2023-10-11
3031

src/_pytask/skipping.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@ def pytask_execute_task_setup(session: Session, task: PTask) -> None:
5454
if is_unchanged and not session.config["force"]:
5555
raise SkippedUnchanged
5656

57-
ancestor_failed_marks = get_marks(task, "skip_ancestor_failed")
58-
if ancestor_failed_marks:
59-
message = "\n".join(
60-
skip_ancestor_failed(*mark.args, **mark.kwargs)
61-
for mark in ancestor_failed_marks
62-
)
63-
raise SkippedAncestorFailed(message)
64-
6557
is_skipped = has_mark(task, "skip")
6658
if is_skipped:
6759
raise Skipped
@@ -74,6 +66,14 @@ def pytask_execute_task_setup(session: Session, task: PTask) -> None:
7466
if should_skip:
7567
raise Skipped(message)
7668

69+
ancestor_failed_marks = get_marks(task, "skip_ancestor_failed")
70+
if ancestor_failed_marks:
71+
message = "\n".join(
72+
skip_ancestor_failed(*mark.args, **mark.kwargs)
73+
for mark in ancestor_failed_marks
74+
)
75+
raise SkippedAncestorFailed(message)
76+
7777

7878
@hookimpl
7979
def pytask_execute_task_process_report(

tests/test_skipping.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,37 @@ def test_pytask_execute_task_setup(marker_name, force, expectation):
270270

271271
with expectation:
272272
pytask_execute_task_setup(session=session, task=task)
273+
274+
275+
def test_skip_has_precendence_over_ancestor_failed(runner, tmp_path):
276+
source = """
277+
from pathlib import Path
278+
279+
def task_example(produces=Path("file.txt")):
280+
raise Exception
281+
282+
def task_example_2(path=Path("file.txt")): ...
283+
"""
284+
tmp_path.joinpath("task_example.py").write_text(textwrap.dedent(source))
285+
result = runner.invoke(cli, [tmp_path.as_posix()])
286+
assert result.exit_code == ExitCode.FAILED
287+
assert "1 Failed" in result.output
288+
assert "1 Skipped" in result.output
289+
290+
291+
def test_skipif_has_precendence_over_ancestor_failed(runner, tmp_path):
292+
source = """
293+
from pathlib import Path
294+
import pytask
295+
296+
def task_example(produces=Path("file.txt")):
297+
raise Exception
298+
299+
@pytask.mark.skipif(True, reason="God knows.")
300+
def task_example_2(path=Path("file.txt")): ...
301+
"""
302+
tmp_path.joinpath("task_example.py").write_text(textwrap.dedent(source))
303+
result = runner.invoke(cli, [tmp_path.as_posix()])
304+
assert result.exit_code == ExitCode.FAILED
305+
assert "1 Failed" in result.output
306+
assert "1 Skipped" in result.output

0 commit comments

Comments
 (0)