Crossing out and forcing results
Crossing Out Results
All test results except Skip result can be crossed out, including OK. This functionality is useful when one or more tests fail and you don’t want to see the next run fail because of the same test failing.
Crossing out a result means converting it to the corresponding crossed out result
that starts with X.
✋ The concept of crossing out a result should not be confused with expected results. It is invalid to say that, for example, XFail, means an expected fail. In general, if you expect a fail, then if the result of the test is Fail, then the final test result is OK and any other result would cause the final result to be Fail as the expectation was not satisfied.
The correct way to think about crossed out results is to imagine that a test summary report is printed on a paper, and after looking over the test results and performing some analysis, any result can be crossed out with an optional reason.
Only the result that exactly matches the result to be crossed out is actually crossed out. For example, if you want to cross out Fail result of the test but the test has a different result, then it will not be crossed out.
The actual crossing out of the results is done by specifying either xfails parameter of the test or using XFails decorator.
In general, the xfails are set at the level of the top test. For example,
1 |
|
All the patterns are usually specified using relative form and are anchored to the top level test during the assignment.
Setting or Clearing Flags
Test flags can be set or cleared externally using xflags or XFlags decorator. As long as the pattern has a chance of matching, this test attribute is pushed down the test tree from parent test to child tests.
This allows setting or clearing flags for any child test at any level of the test tree including at the top level test.
For example,
1 |
|
Forcing Results
Test results can be forced, and the body of the test can be skipped by using ffails or FFails decorator. As long as the pattern has a chance of matching, this test attribute is pushed down the test tree from parent test to child tests
This enables the result of any child test to be force at any level of the test tree, including at the top level test.
✋ When a test result is forced, the body of the test is not executed.
For example,
1 |
|
The optional when function can also be specified.
1 | def version(*versions): |
Forced Result Decorators
Forced result decorators such as Skipped, Failed, XFailed, XErrored, Okayed, and XOkayed can be used to tie the force result right where the test is defined.
✋ When a test result is forced, the body of the test is not executed.
These decorators are just a short-hand form of specifying forced results using ffails test attribute. Therefore, if parent test explicitly specifies ffails then it overrides forced results tied to the test.
✋ Only one such decorator can be applied to a given test. If you want to specify more than one forced result, use FFails decorator.
See also the description for the when condition.
Skipped
The Skipped decorator can be used to force Skip result.
1 |
|
Failed
The Failed decorator can be used to force Fail result.
1 |
|
XFailed
The XFailed decorator can be used to force XFail result.
1 |
|
XErrored
The XErrored decorator can be used to force XError result.
1 |
|
Okayed
The Okayed decorator can be used to force OK result.
1 |
|
XOkayed
The XOkayed decorator can be used to force XOK result.
1 |
|