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 withpassed=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:
Name | Type | Default | Description |
---|---|---|---|
passed | Optional[bool] | True | Whether the step passed or not. |
message | Optional[str] | None | The success/failure message from the task. |
exec_time | Optional[float] | 0 | How long the step took to take in seconds. |
failed_urls | Optional[list[str]] | [] | Any URLs that failed a test. |
exc | Optional[Exception] | None | The 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).