[lang-ref] ( assignment_expression_in_conditional_block ) ( python )

@pytest.mark.parametrize(
    'pattern, expected',
    [
        (r'd.f' , 'def'),
        (r'XYZ' , ''),
    ],
)
def test_assignment_expression_in_conditional_block(pattern, expected):
    # :=
    # 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