Cucumber Tag Expressions

9.1.0 · active · verified Fri Apr 10

cucumber-tag-expressions provides a parser and evaluation logic for boolean tag expressions, commonly used in Cucumber and Behave for filtering scenarios. It is currently at version 9.1.0 and is actively maintained across multiple language implementations, with Python-specific updates occurring as needed.

Warnings

Install

Imports

Quickstart

This example demonstrates how to parse a tag expression string and then use the resulting evaluator function to check if a given set of tags matches the expression.

from cucumber_tag_expressions import parse

# Define a tag expression
expression_string = "@smoke and not @wip"

# Parse the expression to get an evaluator function
tags_evaluator = parse(expression_string)

# Define a set of tags to test against
scenario_tags_1 = {"@smoke", "@ui"}
scenario_tags_2 = {"@smoke", "@feature", "@not_wip"}
scenario_tags_3 = {"@smoke", "@wip"}

# Evaluate the expression against different sets of tags
result_1 = tags_evaluator(scenario_tags_1)
result_2 = tags_evaluator(scenario_tags_2)
result_3 = tags_evaluator(scenario_tags_3)

print(f"Expression '{expression_string}' against {scenario_tags_1}: {result_1}")
print(f"Expression '{expression_string}' against {scenario_tags_2}: {result_2}")
print(f"Expression '{expression_string}' against {scenario_tags_3}: {result_3}")

# Expected output:
# Expression '@smoke and not @wip' against {'@ui', '@smoke'}: True
# Expression '@smoke and not @wip' against {'@feature', '@not_wip', '@smoke'}: True
# Expression '@smoke and not @wip' against {'@wip', '@smoke'}: False

view raw JSON →