Timeouts and conditions
Test Timeouts
You can set test timeouts using the timeouts parameter.
Timeouts
The Timeouts object can be either used as the value of the timeouts parameter or as a decorator that can be applied to any decorated test.
The Timeouts takes as an argument a list of objects that specify a timeout, either using the Timeout object directly or as a tuple of arguments that will be passed to it.
1 | [ |
The Timeouts decorator should be used when you want to specify more than one timeout.
✋ Even though more than one timeout can be specified, only the value with the smallest value will be the effective timeout.
1 |
|
For a single timeout, the Timeout decorator can be used instead.
Timeout
The Timeout object can be either used as one of the values in the list passed to the timeouts parameter or as a decorator that can be applied to any decorated test.
1 | Timeout(timeout, message=None, started=None, name=None) |
where
timeouttimeout in secmessagecustom timeout error message, default:Nonestartedstart time, default:None(set to the current test’s start time)namename, default:None
For example,
1 | with Test("my test", timeouts=[Timeout(10)]): |
or it can be used as a decorator as follows:
1 |
|
The when Condition
Some parameters support a when condition, specified as a function, as the last element.
If present, the when function is called before test execution.
The boolean result returned by the when function determines if the forced result is applied,
if the function returns True, or not, if it returns False.
The when function must take one argument, which is the instance of the test.
✋ The optional
whenfunction can define any logic that is needed to determine if some condition is met. Any callable that takes a current test object as the first and only argument that can be used.
Here is an example of using ffails with a when condition:
1 | def version(*versions): |
Specialized keywords
when writing your test scenarios, the framework encourages the usage of specialized keywords because they can provide the much-needed context for your steps.
The specialized keywords map to core Step, Test, Suite, and Module test definition classes as follows:
- Module is defined as a Module
- Suite is defined as a Feature
- Test is defined as a Scenario
- Step is defined as one of the following:
- Given is used define a step for precondition or setup
- Background is used define a step for a complex precondition or setup
- When is used to define a step for an action
- And is used as a continuation of the previous step
- By is used to define a sub-step
- Then is used to define a step for positive assertion
- But is used to define a step for negative assertion
- Finally is used to define a cleanup step