Commit 26e1667b authored by Vincent Stehlé's avatar Vincent Stehlé
Browse files add an option to filter tests data

Allow to filter tests data using a python expression. This complements the
existing key/value filtering mechanism.

Signed-off-by: Vincent Stehlé's avatarVincent Stehlé <>
parent d50a24ac
......@@ -32,6 +32,21 @@ $ ./ --sort \
'group,descr,set guid,test set,sub set,guid,name,log' ...
### Filtering data
The `--filter` option allows to specify a python3 expression, which is used as a
filter. The expression is evaluated for each test; if it evaluates to True the
test is kept, otherwise it is omitted. The expression has access to the test
as dict "x".
Example command, which keeps only the failed tests:
``` {.sh}
$ ./ --filter "x['result'] == 'FAILURE'" ...
Filtering takes place after the configuration rules, which are described below.
## Configuration file
It is possible to use a configuration file with command line option `--config
......@@ -315,6 +315,21 @@ def use_config(cross_check, filename):
apply_rules(cross_check, conf)
# Filter tests data
# Filter is a python expression, which is evaluated for each test
# When the expression evaluates to True, the test is kept
# Otherwise it is dropped
def filter_data(cross_check, Filter):
logging.debug(f"Filtering with `{Filter}'")
# This function "wraps" the filter and is called for each test
def function(x):
return eval(Filter)
return list(filter(function, cross_check))
# Sort tests data in-place
# sort_keys is a comma-separated list
# The first key has precedence, then the second, etc.
......@@ -486,6 +501,7 @@ def main():
'--debug', action='store_true', help='Turn on debug messages')
'--sort', help='Comma-separated list of keys to sort output on')
parser.add_argument('--filter', help='Python expression to filter results')
'log_file', nargs='?', default='sample.ekl',
help='Input .ekl filename')
......@@ -536,6 +552,10 @@ def main():
if 'config' in args and args.config is not None:
use_config(cross_check, args.config)
# Filter tests data, if requested
if args.filter is not None:
cross_check = filter_data(cross_check, args.filter)
# Sort tests data in-place, if requested
if args.sort is not None:
sort_data(cross_check, args.sort)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment