Skip to content
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

Add test for allow_failure and quote #8055

Merged
merged 6 commits into from
Jan 6, 2023
Merged
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
47 changes: 46 additions & 1 deletion src/prefect/testing/standard_test_suites/task_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
from prefect import flow, task
from prefect.client.schemas import TaskRun
from prefect.deprecated.data_documents import DataDocument
from prefect.logging import get_run_logger
from prefect.orion.schemas.states import StateType
from prefect.states import State
from prefect.states import Crashed, State
from prefect.task_runners import BaseTaskRunner, TaskConcurrencyType
from prefect.testing.utilities import exceptions_equal
from prefect.utilities.annotations import allow_failure, quote


class TaskRunnerStandardTestSuite(ABC):
Expand Down Expand Up @@ -654,3 +656,46 @@ async def test_flow():
await test_flow()

assert tmp_file.read_text() == "foo"

def test_allow_failure(self, task_runner, caplog):
@task
def failing_task():
raise ValueError("This is expected")

@task
def depdendent_task():
logger = get_run_logger()
logger.info("Dependent task still runs!")
return 1

@task
def another_dependent_task():
logger = get_run_logger()
logger.info("Sub-dependent task still runs!")
return 1

@flow(task_runner=task_runner)
def test_flow():
ft = failing_task.submit()
dt = depdendent_task.submit(wait_for=[allow_failure(ft)])
another_dependent_task.submit(wait_for=[dt])

with pytest.raises(ValueError, match="This is expected"):
test_flow()
assert len(caplog.records) == 2
assert caplog.records[0].msg == "Dependent task still runs!"
assert caplog.records[1].msg == "Sub-dependent task still runs!"

def test_passing_quoted_state(self, task_runner):
@task
def test_task():
state = Crashed()
return quote(state)

@flow(task_runner=task_runner)
def test_flow():
return test_task()

result = test_flow()
assert isinstance(result, quote)
assert isinstance(result.unquote(), State)