Skip to main content

Task Result

Each step calculates to either a pass or fail. A task by default passes. The following conditions cause a test to fail:

  • The step raises an uncaught exception
  • The step manually returns a TaskResult object with passed=False
  • The step returns False

If the step returns any other value, it is assumed to have passed. Here are some examples:

class Test(Task):
# fails with a message `"This step fails"`
@step()
def step_1(self):
assert False, "This step fails"

# passes
@step()
def step_2(self):
return True

# passes with a message `"This step passes"`
@step()
def step_3(self):
return "This step passes"

# fails
@step()
def step_4(self):
return TaskResult(passed=False)

The TaskResult Class

The executed task returns a TaskResult array with the results of each step. The above example would return:

[
TaskResult(passed=False, message="This step fails", exc=AssertionError),
TaskResult(passed=True),
TaskResult(passed=True, message="This step passes"),
TaskResult(passed=False)
]

Configuration

A TaskResult has the following parameters:

NameTypeDefaultDescription
passedOptional[bool]TrueWhether the step passed or not.
messageOptional[str]NoneThe success/failure message from the task.
exec_timeOptional[float]0How long the step took to take in seconds.
failed_urlsOptional[list[str]][]Any URLs that failed a test.
excOptional[Exception]NoneThe exception raised from the step.

This information can be used at the end of a task to manage the result (i.e. send a Slack message or determine the behavior of the host application).