‘parse‘ 是默认的step mathcer, 他被使用最多, 有以下特点
‘cfparse‘ 是parse的扩展, 设计初衷是替代parse, 它有以下特点
‘re‘有以下特点
# -- FILE: features/environment.py from behave import use_step_matcher # -- SELECT DEFAULT STEP MATCHER: Use "re" matcher as default. # use_step_matcher("parse") # use_step_matcher("cfparse") use_step_matcher("re")
# 简单的group捕获, 并赋值给P<test>
# -- SIMPLE GROUP: foo @when(u‘I try to match "(?P<foo>foo)"‘) def step_when_I_try_to_match_foo(context, foo): context.foo = foo # -- SIMPLE GROUP: anything else @when(u‘I try to match "(?P<anything>.*)"‘) def step_when_I_try_to_match_anything_else(context, anything): context.anything = anything
# 可选的的group: (?P<an_>an )?
@when(u‘I try to match (?P<an_>an )?optional "(?P<foo>foo)"‘) def step_when_I_try_to_match_an_optional_foo(context, an_, foo): context.foo = foo context.an_ = an_
# 套嵌的正则
@when(u‘I try to match nested "(?P<foo>foo(?P<bar>bar)?)"‘) def step_when_I_try_to_match_nested_foobar(context, foo, bar): context.foo = foo context.bar = bar
原文:http://www.cnblogs.com/v394435982/p/6402451.html