jd / tenacity

Retrying library for Python
http://tenacity.readthedocs.io
Apache License 2.0
6.82k stars 283 forks source link

bug: `retry_if_exception_message` only checks the beginning of the string #415

Closed Jonas1312 closed 1 year ago

Jonas1312 commented 1 year ago

Hi,

https://github.com/jd/tenacity/blob/310058274ed22a345e9c3917c97b4afd6363d5a5/tenacity/retry.py#L220

re.match(pattern, str) Matches pattern only at the beginning of the string.

Expected behavior: it should match the pattern anywhere in the string

Proposed fix: use re.search(pattern, str)

Thanks!

asqui commented 1 year ago

If you want to match part of the error string why not just prefix (and/or suffix) .* to your pattern string?

I think the change you are proposing would make it impossible to strictly match the full exact error string, which seems undesirable.

Jonas1312 commented 1 year ago

I see, your solution works, thanks

I was confused because the behavior is different to the pytest.raises(match="...")