Messages, metrics and input
Adding Messages
You can add custom messages to your tests using note() function, debug() function, trace() function, and message() function.
✋ Use Python f-strings if you need to format a message using variables.
Using note()
Use note() function to add a note message to your test.
1 | note(message, test=None) |
where
messageis a string that contains your messagetest(optional) the instance of the test to which the message will be added, default: current test
For example,
1 | from testflows.core import * |
when executed shows the note message.
1 | Nov 15,2021 14:17:21 ⟥ Scenario my scenario |
Using debug()
Use debug() function to add a debug message to your test.
1 | debug(message, test=None) |
where
messageis a string that contains your messagetest(optional) the instance of the test to which the message will be added, default: current test
For example,
1 | from testflows.core import * |
when executed shows the debug message.
1 | Nov 15,2021 14:19:27 ⟥ Scenario my scenario |
Using trace()
Use trace() function to add a trace message to your test.
1 | trace(message, test=None) |
where
messageis a string that contains your messagetest(optional) the instance of the test to which the message will be added, default: current test
For example,
1 | from testflows.core import * |
when executed shows the trace message.
1 | Nov 15,2021 14:20:17 ⟥ Scenario my scenario |
Using message()
Use message() function to add a generic message to your test
that could optionally be assigned to a stream.
1 | message(message, test=None, stream=None) |
where
messageis a string that contains your messagetest(optional) the instance of the test to which the message will be added, default: current teststream(option) is a stream with which the message should be associated
For example,
1 | from testflows.core import * |
when executed shows the custom message.
1 | Nov 15,2021 14:37:53 ⟥ Scenario my scenario |
Using exception()
Use exception() function to manually add an exception message to your test.
1 | exception(exc_type, exc_value, exc_traceback, test=None) |
where
exc_typeexception typeexc_valueexception valueexc_tracebackexception tracebacktest(optional) the instance of the test to which the message will be added, default: current test
✋ The
exc_type,exc_value, andexc_tracebackare usually obtained from sys.exc_info() that must be called withinexceptblock.
For example,
1 | import sys |
when executed shows the exception message.
1 | Nov 15,2021 15:08:48 ⟥ Scenario my scenario |
Adding Metrics
You can add metric messages to your test using metric() function.
1 | metric(name, value, units, type=None, group=None, uid=None, base=Metric, test=None) |
where
namename of the metricvaluevalue of the metricunitsunits of the metric (string)type(optional) metric typegroup(optional) metric groupuid(optionl) metric unique identifierbase(optional) metric base class, default: Metric classtest(optional) the instance of the test to which the message will be added, default: current test
For example,
1 | from testflows.core import * |
when executed shows the metric message.
1 | Nov 15,2021 16:44:13 ⟥ Scenario my scenario |
You can use cat test.log | tfs show metrics command to see all the metrics for a given test.
See Show Metrics and Metrics Report.
For example,
1 | cat test.log | tfs show metrics |
1 | Scenario /my scenario |
Reading Input
You can read input during test program execution using input() function. This function is commonly used in Semi-Automated And Manual Tests.
1 | input(type, multiline=False, choices=None, confirm=True, test=None |
where
typeis either a string orresultfunction.multiline(optional) flag to indicate if input is multiline string, default:Falsechoices(optional) a list of valid options (only applies iftypeis string)confirm(optional) request confirmation, default:Truetestthe instance of the test that will be associated with the input message, default: current test
For example,
1 | from testflows.core import * |
when executed prompts for input
1 | Nov 15,2021 17:19:25 ⟥ Scenario my scenario |
Also, you can prompt for the result. For example,
1 | from testflows.core import * |
when executed prompts for result
1 | Nov 15,2021 17:22:26 ⟥ Scenario my scenario |