Skip to content

Give skips higher precendence than ancestor failed as outcome. #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
- {pull}`473` adds signatures to nodes which decouples an identifier from a name.
- {pull}`477` updates the PyPI action.
- {pull}`478` replaces black with ruff-format.
- {pull}`479` gives skips a higher precedence as an outcome than ancestor failed.

## 0.4.1 - 2023-10-11

Expand Down
16 changes: 8 additions & 8 deletions src/_pytask/skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ def pytask_execute_task_setup(session: Session, task: PTask) -> None:
if is_unchanged and not session.config["force"]:
raise SkippedUnchanged

ancestor_failed_marks = get_marks(task, "skip_ancestor_failed")
if ancestor_failed_marks:
message = "\n".join(
skip_ancestor_failed(*mark.args, **mark.kwargs)
for mark in ancestor_failed_marks
)
raise SkippedAncestorFailed(message)

is_skipped = has_mark(task, "skip")
if is_skipped:
raise Skipped
Expand All @@ -74,6 +66,14 @@ def pytask_execute_task_setup(session: Session, task: PTask) -> None:
if should_skip:
raise Skipped(message)

ancestor_failed_marks = get_marks(task, "skip_ancestor_failed")
if ancestor_failed_marks:
message = "\n".join(
skip_ancestor_failed(*mark.args, **mark.kwargs)
for mark in ancestor_failed_marks
)
raise SkippedAncestorFailed(message)


@hookimpl
def pytask_execute_task_process_report(
Expand Down
34 changes: 34 additions & 0 deletions tests/test_skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,37 @@ def test_pytask_execute_task_setup(marker_name, force, expectation):

with expectation:
pytask_execute_task_setup(session=session, task=task)


def test_skip_has_precendence_over_ancestor_failed(runner, tmp_path):
source = """
from pathlib import Path

def task_example(produces=Path("file.txt")):
raise Exception

def task_example_2(path=Path("file.txt")): ...
"""
tmp_path.joinpath("task_example.py").write_text(textwrap.dedent(source))
result = runner.invoke(cli, [tmp_path.as_posix()])
assert result.exit_code == ExitCode.FAILED
assert "1 Failed" in result.output
assert "1 Skipped" in result.output


def test_skipif_has_precendence_over_ancestor_failed(runner, tmp_path):
source = """
from pathlib import Path
import pytask

def task_example(produces=Path("file.txt")):
raise Exception

@pytask.mark.skipif(True, reason="God knows.")
def task_example_2(path=Path("file.txt")): ...
"""
tmp_path.joinpath("task_example.py").write_text(textwrap.dedent(source))
result = runner.invoke(cli, [tmp_path.as_posix()])
assert result.exit_code == ExitCode.FAILED
assert "1 Failed" in result.output
assert "1 Skipped" in result.output