[lang-ref] Assignment expression in conditional block ( walrus ) ( python )
@pytest.mark.parametrize(
'pattern, expected',
[
(r'd.f' , 'def'),
(r'XYZ' , ''),
],
)
def test_assignment_expression_in_conditional_block(pattern, expected):
# := ( walrus )
# Note: from Python 3.8, Walrus Operator
text = 'abcdef abcdef abcdef'
if (m := re.search(pattern, text)) is not None:
actual = m.group(0)
else:
actual = ''
assert actual == expected