Controlling output
Controlling Output
Test output can be controlled with -o or --output option, which specifies the output format to use
to print to stdout. By default, the most detailed nice output is used.
1 | -o format, --output format stdout output format, choices are: ['new-fails', |
For example, you can use the following test and see how the output format changes based on the output that is specified.
test.py
1
2
3
4
5
6
7
8 from testflows.core import *
with Module("regression", flags=TE, attributes=[("name","value")], tags=("tag1", "tag2")):
with Scenario("my test", description="Test description."):
with When("I do something"):
note("do something")
with Then("I check the result"):
note("check the result")
nice Output
The nice output format is the default output format and provides the most
details when developing and debugging tests. This output format includes all test types,
their attributes and results, as well as any messages that are associated with them.
✋ This output format is the most useful for developing and debugging an individual test. This output format is not useful when tests are executed in parallel.
For example,
1 | python3 test.py --output nice |
1 | Sep 25,2021 9:29:39 ⟥ Module regression, flags:TE |
produces the same output as when --output is omitted.
1 | python3 test.py |
brisk Output
The brisk output format is very similar to nice output format but
omits all steps (tests that have Step Type). This format is useful when
you would like to focus on the actions of the test, such as commands executed
on the system under test, rather than on the test procedure itself.
✋ This output format is useful for debugging individual tests when you would like to omit test steps. This output format is not useful when tests are executed in parallel.
1 | python3 output.py -o brisk |
1 | Sep 25,2021 12:05:25 ⟥ Module regression, flags:TE |
short Output
The short output format provides a shorter output than nice output format
as only test and result messages are formatted.
✋ This output format is very useful to highlight and verify test procedures. This output format is not useful when tests are executed in parallel.
1 | python3 test.py -o short |
1 | Module regression |
classic Output
The classic output format shows only full test names for
any test with a Test Type of higher will receive test and result messages.
Tests with Step Type are not displayed.
✋ This output format can be used for CI/CD runs as long as the number of tests is not too large. This output format can be used when tests are executed in parallel.
1 | python3 test.py -o classic |
1 | ➤ Sep 25,2021 11:14:15 /regression |
progress Output
The progress output format shows the progress of the test run.
The output is always printed on one line on progress updates and is useful
when running tests locally.
Any test failures are printed inline as soon as they occur.
✋ This output format should not be used for CI/CD runs as it outputs terminal control codes to update the same line. This output format can be used when tests are executed in parallel.
1 | python3 test.py -o progress |
1 | Executing 2 tests /regression/my test/I do something |
fails Output
The fails output format only shows failing results Fail, Error, and Null
and crossed out the results XFail, XError, XNull, XOK.
Failing results are only shown for tests with Test Type of higher.
✋ This output format can be used for CI/CD runs as long as the number of crossed-out results is not too large; otherwise, use
new-failsoutput format instead. This output format can be used when tests are executed in parallel.
1 | python3 test.py -o fails |
1 | ✘ 3ms [ XFail ] /regression/my test |
new-fails Output
The new-fails output format only shows failing results Fail, Error, and Null.
Crossed out results are not shown.
Failing results are only shown for tests with Test Type of higher.
✋ This output format can be used for CI/CD runs. This output format can be used when tests are executed in parallel.
1 | python3 test.py -o new-fails |
1 | ✘ 3ms [ Fail ] /regression/my test |
slick Output
The slick output format provides even shorter output than short output format
as it only shows test and result messages for any test that has Test Type of higher.
Tests that have Step Type are not showed.
✋ This output format is more eye-candy. This output format is not useful when tests are executed in parallel.
1 | python3 test.py --output slick |
1 | ➤ Module regression |
quiet Output
The quiet output format does not output anything to stdout.
✋ This output format can be used for CI/CD runs. This output format can be used when tests are executed in parallel.
1 | python3 test.py -o quiet |
manual Output
The manual output format is only suitable for running manual or semi-automated
tests where the tester is constantly prompted for input. The terminal screen is always cleared
before starting any test with Test Type or higher.
✋ This output format is only useful for manual or semi-automated tests.
1 | python3 test.py -o manual |
raw Output
The raw output format outputs raw messages.
✋ This output format is only useful for TestFlows developers and curious users who want to understand what raw messages look like.
1 | python3 test.py -o raw |
1 | {"message_keyword":"PROTOCOL","message_hash":"1336ea41","message_object":0,"message_num":0,"message_stream":null,"message_level":1,"message_time":1632584893.162271,"message_rtime":0.009011,"test_type":"Module","test_subtype":null,"test_id":"/fd823a2c-1e17-11ec-8830-cb614fe11752","test_name":"/regression","test_flags":1,"test_cflags":0,"test_level":1,"protocol_version":"TFSPv2.1"} |
Advanced users can use this format to apply custom message transformations.
For example, it can be transformed using tfs transform nice command into nice
format
1 | python3 test.py -o raw | tfs transfrom nice |
or combined with other unix tools such as grep with further message transformations.
1 | python3 output.py -o raw | grep '{"message_keyword":"RESULT",' | tfs transform nice |
Summary Reports
Most output formats include one or more summary reports. These reports are printed after all tests have been executed.
✋ Most summary reports only include tests that have Test Type or higher. Tests with Step Type are not included.
Passing
This report generates Passing section and show passing tests.
1 | Passing |
Failing
This report generates Failing section and shows failing tests.
1 | Failing |
Known
This report generates Known section.
1 | Known |
Unstable
This report generates Unstable section. Tests are considered unstable
if they are repeated and different iterations have different results.
1 | Unstable |
Coverage
This report generates Coverage section. It is only generated if
at least one Specification is attached to any of the tests and shows
requirements coverage statistics for each Specification.
1 | Coverage |
Totals
This report generates test counts and total test time section.
1 | 1 module (1 ok) |
Version
This report generates a message that shows the date time of the test run and the version of the framework that was used to run the test program.
1 | Executed on Sep 25,2021 12:05 |
Turning Off Color Highlighting
There are times when color highlighting might be in the way. For example, when piping output to a different utility or saving it into the file. In both of these cases, use --no-colors to tell TestFlows to turn off adding terminal control color codes.
1 | python3 test.py --no-colors > nice.log |
or
1 | python3 test.py --no-colors | less |
The same option can be specified for the tfs utility.
1 | cat test.log | tfs --no-colors show messages |
or
1 | tail -f test.log | tfs --no-colors transform nice | less |
Use --no-colors in Code
You can also detect if terminal color codes are turned off in code
by looking at settings.no_colors attribute, as follows
1 | import testflows.settings as settings |
Forcing To Abort on First Fail
You can force a test program to abort on first failure irrespective of the presence of TE flags by using --first-fail test program argument.
For example,
1 | python3 test.py --first-fail |
Forcing To Continue on Fail
You can force the test program to continue running if any of the tests fail irrespective of the presence of TE flags by using --test-to-end test program argument.
For example,
1 | python3 test.py --test-to-end |
Enabling Debug Mode
You can enable debug mode by specifying --debug option to your test program. When debug mode is enabled, the tracebacks will include more details, such as internal function calls inside the framework that are hidden by default to reduce clutter.
1 | python3 test.py --debug |
Use --debug in Code
You can also trigger actions in your test code based on if --debug option
was specified or not. When --debug option is specified, the value
can be retrieved from settings.debug as follows
1 | import testflows.settings as settings |
Getting Test Time
Using current_time()
✨ Available in 1.7.57
You can get current test execution time using current_time() function.
1 | current_time(test=None) |
where
test(optional) the instance of the test for which a test time should be obtained, default: current test
The returned value is fixed after test has finished its execution.
For example,
1 | from testflows.core import * |
Show Test Data
After the test program is executed, you can retrieve different test data related to the test run
using tfs show command.
The following commands are available:
1 | tfs show -h |
1 | commands: |
Show Metrics
Use tfs show metrics command to show metrics for a given test.
1 | positional arguments: |
For example,
1 | cat test.log | tfs show metrics |